-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
76 lines (67 loc) · 1.99 KB
/
app.py
File metadata and controls
76 lines (67 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import dash
from dash import html
from dash.dependencies import Input, Output
from dash_vite_plugin import VitePlugin, NpmPackage
# Create VitePlugin instance with Vue support
vite_plugin = VitePlugin(
build_assets_paths=['assets/js', 'assets/vue'],
entry_js_paths=['assets/js/main.js'],
npm_packages=[
NpmPackage('vue'),
],
download_node=True,
clean_after=True,
)
# Call setup BEFORE creating Dash app (as required by the plugin architecture)
vite_plugin.setup()
# Create a Dash app
app = dash.Dash(__name__)
# Call use AFTER creating Dash app (as required by the plugin architecture)
vite_plugin.use(app)
# Define app layout with a container for Vue
app.layout = html.Div(
[
html.H1('Vite Plugin Test - Vue Support', id='header'),
html.P('This tests the Vite plugin with Vue support.', id='paragraph'),
# Container for Vue app
html.Div(
[
'The content from Vue',
html.Div(id='vue-container'),
]
),
html.Div(
[
'The content from Dash',
html.Div(
[html.H1('Hello from Dash!', id='dash-title'), html.Button('Control Vue', id='dash-button')],
id='dash-app',
style={'margin': '20px'},
),
],
id='dash-container',
),
]
)
# Add callback to test Vue functionality with a simpler approach
app.clientside_callback(
"""
function(n_clicks) {
if (n_clicks > 0) {
const vueApp = document.getElementById('vue-app');
if (vueApp) {
const button = vueApp.querySelector('#control-vue-button');
if (button) {
button.click();
return 'Hello from Dash!';
}
}
}
return 'Hello from Dash!';
}
""",
Output('dash-title', 'children'),
Input('dash-button', 'n_clicks'),
)
if __name__ == '__main__':
app.run(debug=True)