【发布时间】:2021-09-23 23:37:45
【问题描述】:
我指的是this post,以便我可以使用来自 Dash Web 应用程序中不同选项卡的数据。
但我无法使用dash.properties.Synced 并收到错误AttributeError: module 'dash' has no attribute 'properties'。
示例代码
import dash
import dash_html_components as html
import dash_core_components as dcc
import dash_daq as daq
from dash.dependencies import Input, Output, State
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.config["suppress_callback_exceptions"] = True
app.layout = html.Div([
dcc.Store(id="num_output", storage_type='session',),
dcc.Tabs(id='tabs-example', value='tab-1', children=[
dcc.Tab(label='Tab one', value='tab-1'),
dcc.Tab(label='Tab two', value='tab-2'),
]),
html.Div(id='tabs-example-content')
])
@app.callback(Output('tabs-example-content', 'children'),
Input('tabs-example', 'value'))
def render_content(tab):
if tab == 'tab-1':
return html.Div([
html.H3('Tab content 1'),
# dcc.Store(id="num_output", storage_type='local',), # session, local
html.Div(id="num_output2",),
html.Div([daq.NumericInput(
id="num_input",
label='Vehicles',
labelPosition='top',
value=dash.properties.Synced(
id='store_model',
property='data',
default=4
),
), ], style={'marginLeft': 20, 'marginRight': 20, 'width': '5%', 'display': 'inline-block'}),
])
elif tab == 'tab-2':
return html.Div([
html.H3('Tab content 2'),
html.Div(id="num_output2",),
])
@app.callback(
Output('num_output', 'data'),
Input('num_input', 'value'))
def render_content(data):
return data
@app.callback(
Output('num_output2', 'children'),
Input('num_output', 'modified_timestamp'),
State('num_output', 'data'))
def render_content(ts, data):
if data:
return html.H4(f'out {data}')
if __name__ == '__main__':
app.run_server(debug=True)
【问题讨论】:
标签: python tabs synchronization store plotly-dash