我有一个多页/制表符破折号应用程序,经常在页面/制表符之间切换。我有一个plotly Graph
,一个mapbox
组件,单击按钮即可更新。
我希望能够保存graph
的状态并在其他标签/功能中引用它。对于输入和其他字段,我使用了persistence
属性,但是,我没有看到对Graph figure
执行相同操作的方法。
layout = html.Div([
dash_table.DataTable(id='dt-table'),
dcc.Graph(id='map-graph1'),
dbc.Button("Run", id="run-button"),
]),
# Update map graph
@app.callback(Output("map-graph1", "figure"),
[
Input("address", "value"),
Input("type", "value"),
Input("button", "n_clicks")
]
)
def update_graph(address, type, n_clicks):
data = []
....
....
....
....
data.append({
"type": "scattermapbox",
"lat": [lat],
"lon": [lng],
"name": "Location",
"showlegend": False,
"hoverinfo": "text",
"mode": "markers",
"marker": {
"symbol": "circle",
"size": 12,
"opacity": 0.7
}
}
)
# Get lat long from geocoding api
if n_clicks:
result = calc_func(address, type)
# Property Location
data.append({
"type": "scattermapbox",
"lat": [Lat],
"lon": [Long],
"hovertext": price,
"textfont": {"size": 22},
"textposition": 'top-right',
"showlegend": False,
"hoverinfo": "text",
"mode": "text+markers",
"marker": {
"symbol": "suitcase",
"size": 28,
"opacity": 0.7
}
}
)
layout = {
"autosize": True,
"hovermode": "closest",
"mapbox": {
"accesstoken": MAPBOX_KEY,
"bearing": 0,
"center": {
"lat": layout_lat,
"lon": layout_lon
},
"pitch": 0,
"zoom": zoom,
"style": "outdoors",
}
}
return {"data": data, "layout": layout}
# Update DataTable
@app.callback(Output("comps-table", "data"),
[
Input("address", "value"),
Input("type", "value"),
Input("comps-button", "n_clicks")
]
)
def update_table(address, type, n_clicks):
if n_clicks:
result = calc_func(address, type, market)
result_df = result['df_lease']
df = pd.DataFrame(result_df, columns = ['Address','Type','Market'])
df = df[df['Type'] == "Type1"]
df_data = df.to_dict('rows')
return (df_data)
else:
return (no_update)