【问题标题】:How to have Dash Plotly page update automatically with gspread data from spreadsheet?如何使用电子表格中的 gspread 数据自动更新 Dash Plotly 页面?
【发布时间】:2021-11-06 22:17:46
【问题描述】:

我正在使用 gspread 库从 Google 电子表格中提取数据,并且我希望我的 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 页面上更新它。

【问题讨论】:

    标签: python python-3.x plotly-dash gspread


    【解决方案1】:

    这就是callbacks 的用途。

    现在我不知道您希望根据输入值以何种方式更改值,但根据您的示例,它可能看起来像这样:

    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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-05
      • 2022-01-23
      相关资源
      最近更新 更多