[英]How to persist state of plotly graph in Dash App
我有一个multi-tab
, subtabs
破折号应用程序。 我希望能够在它们之间切换时在不同的子选项卡中保存/保持组件的状态。 这些组件是dropdown, input, graph, slider, daterange
等。
我使用组件的持久性属性,它适用于输入、下拉、滑块但不适用于图形。 我想保留dcc.Graph
组件的状态, dcc.Graph
组件呈现绘图可视化。
dcc.Tabs(
id="tabs",
vertical=True,
persistence=True,
children=[
dcc.Tab(label="Tab 1", value="tab1"),
dcc.Tab(label="Tab 2", value="tab2",
children=[dcc.Tabs(id="subtabs",
persistence=True,
children=[dcc.Tab(label='a', value='ab'),
dcc.Tab(label='z' value='wv')
],
)
]),
],
)
dash 中是否有本地解决方案可以保存应用程序的状态? 谢谢。
我在开发dash应用程序时遇到了这个问题。 在不同页面之间切换时,我需要缓存数字。 尝试存储它们时调整 storage_type 对我有用: https : //dash.plotly.com/dash-core-components/store
伪代码:
@app.callback(
Output('plt','figure'),
Input('url','pathname'), # use url to trigger callbacks
Input('plt,'figure'),
State('plt-cached','data'),
):
def render_fig(url,plt,plt-cached):
if url != 'cached_page': raise PreventUpdate
if not plt: # when switching between pages, dcc.Store('plt') is refreshed when set to 'memory'
return plt-cached
# other functions/code to render the plot in your own application
# callback functions to cache figure
@app.callback(
Output('plt-cached','data'), # dcc.Store('plt-cached') is set to `storage_type=session`
Input('plt','figure'),
)
def cache_fig(plt):
return plt
我的实际应用程序比上面的例子复杂得多,如果你直接复制/粘贴上面的应用程序可能不起作用,因为我什至没有干运行它。 但是,您可以获得解决自己问题的线索:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.