@Sourdough wrote:
Hi, everyone
I have a problem when i build a web server.
Because i want to separate different app for my website, I need to dynamic import the sub-callback(for the app).Here is my problem:
When I first open the web site(including had opened), the callback graph in timeseries page doesn’t have button function. But when I refresh the browser, and go to the timeseries page again, the callback graph has the button function. Just like the append fig.Did anyone have any idea, please context with me, THANKS!
My web server structure likes:
server folder
app.py
- apps
- index
- timeseries
- apps
- init .py
- callbacks.py
- layout.py
- init.py
and codes likes
def :
<app.py>… … … def _init_callback_map(app): keylist=list(app.callback_map.keys()) # =============================================================== # # Test for initialize callback_map # print(app.callback_map) # print('---------------------') for key in keylist: if key!='page-content.children': app.callback_map.pop('{key}'.format(key=key)) # print(key) # print('---------------------\n') # =============================================================== # # Routing setting @app.callback(Output('page-content', 'children'), [#Input('url', 'pathname'), Input('navi-home','n_clicks_timestamp'), Input('navi-dashboard','n_clicks_timestamp'), Input('navi-timeseries','n_clicks_timestamp'), Input('navi-datatable','n_clicks_timestamp'), Input('navi-absorption','n_clicks_timestamp'), Input('navi-testpage','n_clicks_timestamp')]) # def display_page(pathname, navi_home_click, navi_dashboard_click): def display_page(navi_home_click, navi_dashboard_click, navi_timeseries_click , navi_datatable_click, navi_absorption_click, navi_testpage_click): _init_callback_map(app) app_dict={ 0:'/', 1:'/apps/dashboard', 2:'/apps/timeseries', 3:'/apps/datatable', 4:'/apps/absorption', 5:'/apps/testpage', -1:'404' } timelist=np.array([ navi_home_click, navi_dashboard_click, navi_timeseries_click, navi_datatable_click, navi_absorption_click, navi_testpage_click ]) timelist[timelist==None]=0 index=timelist.argmax() # print(index) pathname=app_dict[index] # print(pathname,index) if pathname == '/': # import callback index from apps.index.callbacks import callbacks as callbacks_index callbacks_index(app) return app_index.layout # elif pathname == '/apps/dashboard': # return app_dashboard.layout elif pathname == '/apps/timeseries': # import callback timeseries from apps.timeseries.callbacks import callbacks as callbacks_timeseries callbacks_timeseries(app) return app_timeseries.layout else: return '404'
<./apps/timeseries/callbacks.py>
… … … def callbacks(app): @app.callback( [Output(component_id='graph', component_property='figure'), Output(component_id='Aerosol_type_signature_figure', component_property='figure'),], [Input(component_id='button_timeseries_update',component_property='n_clicks')], [State(component_id='Select_Time', component_property='start_date'), State(component_id='Select_Time', component_property='end_date'), State(component_id='Species_Dropdown', component_property='value'), State(component_id='Instrument_Dropdown', component_property='value')] ) def update_data(click,start_date,end_date,select_species,select_instrument): start_time=datetime.datetime.strftime( datetime.datetime.strptime(start_date,'%Y-%m-%d')-time_offset, '%Y%m%d%H%M%S' ) end_time=datetime.datetime.strftime( datetime.datetime.strptime(end_date,'%Y-%m-%d')+datetime.timedelta(days=1)-time_offset, '%Y%m%d%H%M%S' ) … … … return …
Posts: 1
Participants: 1