Hi, I am converting my single page code to multi, and I have a couple of issues:
1- When I run page1 individually (with a couple of changes), it runs without an issue, for example, I can get the RadioItems displayed after pressing the submit button, with the multipage, nothing is happening.
2- When I apply the multipage setting, the callback seems not to be excuted.
So, the help that I need is in the following:
1- Execute all the pages, here I am giving only page1, but I will have a couple more
2- I want to share the RadioItems selection among all pages, so how do I setup the dcc.store?
3- Most likely I will need more sharing between other pages, do I need to set the dcc.store for each variable individually?
4- When I run the app.py, it runs and then starts the server, and then goes into the loop again (just one more time), not sure why.
5- The variable that I want to share is the nic_selection.
Help is highly appreciated, here are the codes for app.py and page1.py (by the way, if I run the multipage tutorials, it works fine, so I don’t think it is an issue of versions)
Thanks for the assistance
App.py
import dash
from dash import html, dcc
print('1')
app = dash.Dash(__name__, use_pages=True)
print('1.1')
app.layout = html.Div(
[
# main app framework
html.Div("Python Multipage App with Dash", style={'fontSize':50, 'textAlign':'center'}),
html.Div([
dcc.Link(page['name']+" | ", href=page['path'])
for page in dash.page_registry.values()
]),
html.Hr(),
# content of each page
dash.page_container
]
)
print('1.2')
if __name__ == "__main__":
print('1.3')
app.run(debug=True)
print('1.4')
page1.py
import dash
from dash import dcc, html, Input, Output, Dash, State
import pandas as pd
import os
dash.register_page(__name__, path='/')
app = Dash(__name__)
print('2')
os.system(f'cmd /c path/tshark -D > path/nics.txt')
nics = pd.read_csv(
'path/nics.txt', sep="}", header=None)
nics.fillna(' (Loopback Link, DO NOT select)', inplace=True)
print('2.1')
# print(nics)
# print(nics[1])
# print(type(nics))
app.layout = html.Div([
html.H1(children='Welcome to the Network Traffic Monitoring Dashboard', style={
'text-align': 'center'}),
html.Div([
html.Label(['Please select a graph to start capturing Traffic, then move to page 2:'], style={
'font-weight': 'bold'}),
dcc.RadioItems(
id='nic_selection',
options=nics[1]),
html.Button(id='submit_btn', n_clicks=0, children='Submit'),
html.Div(id='btn_output'),
dcc.Store(id='selection_storage', storage_type='local')
])])
print(2.2)
layout = app.layout
print('2.7')
@app.callback(
[Output('btn_output', 'children'),
Output('selection_storage', 'data')],
[State('nic_selection', 'value')],
[Input('submit_btn', 'n_clicks')]
)
def update_output(value, n_clicks, data):
print('2.3')
# print('data is', data)
if n_clicks == 0:
print('2.4')
raise PreventUpdate
# return ''
print('2.5')
else:
print('2.6')
# # selected_nic.to_csv("D:/OneDrive/NetPredict/codes/multipages/Output.txt")
# text_file = open("D:/OneDrive/NetPredict/codes/multipages/Output.txt", "w")
# text_file.write(data)
# text_file.close()
print('value is', value)
print('2.9')
if __name__ == "__main__":
print('2.91')
app.run_server(debug=True)
print('2.92')