get_app_api_url()
方法用于获取 Plotly Dash 应用程序的 API URL。下面是一个简单的示例,演示如何使用这个方法:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.express as px
# 创建 Dash 应用程序
app = dash.Dash(__name__)
# 布局
app.layout = html.Div([
dcc.Graph(id='scatter-plot'),
html.Button('Update Plot', id='update-button')
])
# 回调函数
@app.callback(
Output('scatter-plot', 'figure'),
[Input('update-button', 'n_clicks')]
)
def update_plot(n_clicks):
if n_clicks is None:
return px.scatter()
# 获取 Plotly Dash 应用程序的 API URL
api_url = app.get_app_api_url()
print(api_url)
# 在这里添加数据处理和绘图的代码
return px.scatter()
if __name__ == '__main__':
app.run_server(debug=True)
在这个示例中,当点击按钮时,会调用 update_plot()
函数来更新散点图。在该函数中,我们使用 get_app_api_url()
方法来获取当前应用程序的 API URL,并在控制台上打印出来。您可以根据需要在这个 URL 上执行其他操作。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:Plotly的get_app_org_url方法怎么使用