簡體   English   中英

如何使用電子表格中的 gspread 數據自動更新 Dash Plotly 頁面?

[英]How to have Dash Plotly page update automatically with gspread data from spreadsheet?

我正在使用 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 頁面上更新。

這就是回調的用途。

現在我不知道您希望根據輸入值以何種方式更改值,但根據您的示例,它可能如下所示:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM