Plotly怎么啟動(dòng)Dash應(yīng)用程序

小億
91
2024-05-16 11:49:26

要啟動(dòng)Dash應(yīng)用程序,您需要在命令行中運(yùn)行Python腳本。首先,確保您已經(jīng)安裝了Dash庫(kù)和Plotly庫(kù)。然后,創(chuàng)建一個(gè)Python腳本來(lái)定義您的Dash應(yīng)用程序。以下是一個(gè)簡(jiǎn)單的示例:

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash(__name__)

app.layout = html.Div(children=[
    html.H1('Hello Dash'),
    dcc.Graph(
        id='example-graph',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
            ],
            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)

保存這個(gè)腳本為app.py,然后在命令行中運(yùn)行以下命令:

python app.py

這將啟動(dòng)Dash應(yīng)用程序,并在瀏覽器中顯示一個(gè)簡(jiǎn)單的數(shù)據(jù)可視化應(yīng)用程序。您可以通過訪問http://127.0.0.1:8050/來(lái)查看和交互應(yīng)用程序。

0