如何使用电子表格中的gspread数据自动更新Dash Plotly页面



我正在使用gspread库从谷歌电子表格中提取数据,我希望我的Dash Plotly页面更新该数据。我有一个输入,我想控制被提取的数据类型。有没有一种方法可以使页面本质上";刷新";在没有实际刷新的情况下,每次输入更改都使用新数据?

html.Div(className='title', children=[
html.H1(className='headers', children=[
AnalysisDashboard.acell('A6').value
]),
html.H2(className='headers', children=[
'Player Report'
]),
dcc.Input(id='idInput', type='number', placeholder='Enter ID'),
html.H1(id='my-output', children=[
'PlaceHolder'
])
])

AnalysisDashboard.acell('A6').value来自外部电子表格,每当我在输入框中输入内容时,我希望它能在Dash Plotly页面上更新。

这就是回调的作用。

现在我不知道你希望根据输入值以什么方式改变值,但根据你的例子,它可能看起来像这样:

from dash import Dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Output, Input
app = Dash(__name__)
app.layout = html.Div(
className="title",
children=[
html.H1(id="output", className="headers", children=["Some initial value"]),
html.H2(className="headers", children=["Player Report"]),
dcc.Input(id="idInput", type="number", placeholder="Enter ID"),
html.H1(id="my-output", children=["PlaceHolder"]),
],
)

@app.callback(
Output("output", "children"),
Input("idInput", "value"),
)
def update_output_div(input_value):
# Replace input_value with whatever you want to return 
# like (AnalysisDashboard.acell('A6').value) or something similar
return input_value

if __name__ == "__main__":
app.run_server()

最新更新