【发布时间】:2022-07-02 04:01:09
【问题描述】:
我是 plotly dash python 的新手。在输入值并单击“设置”按钮后,我需要帮助更新图表。我尝试了很多方法,但我无法使它正确。此外,刷新按钮用于将图形刷新回 0 输入值。我被困在这里了。我必须在输入后更新图表还是只更新值?
from dash import html, Dash, dcc, Input, Output, State
import plotly.express as px
import pandas as pd
app = Dash(__name__)
df = pd.DataFrame({
"Minimum/Maximum":["Minimum", "Maximum"],
"Numbers of Beat": [2,60]
})
fig = px.bar(df, x = "Minimum/Maximum", y = "Numbers of Beat", color="Minimum/Maximum")
app.layout = html.Div(
children=[
html.H1(children= 'HTML Dashboard Application'),
html.Div(children=
'''
Dash: Minimum/Maximum Bar Graph
'''),
dcc.Graph(
id='dash_graph',
figure = fig
),
html.Div(dcc.Input(placeholder='Enter a min value...' ,id='min_value', type='text')),
html.Div(dcc.Input(placeholder='Enter a max value...' ,id='max_value', type='text')),
html.Button(id='Set-val', n_clicks=0, children= 'Set'),
html.Button(id='Refresh_current_BPM', n_clicks=0, children= 'Refresh'),
])
@app.callback(
Output('dash_graph', 'figure'),
Input('Set-val', 'n_clicks'),
State('min_value', 'value'),
State('max_value', 'value')
)
def update_value(min_value, max_value, n_clicks):
#new value should appear in the graph here
return fig
if __name__ == '__main__':
app.run_server(debug = True)
【问题讨论】:
标签: python plotly plotly-dash