Plotly怎么获取应用程序缓存URL
要获取Plotly应用程序的缓存URL,您可以使用dash_clientside
模块中的app.get_relative_path
函数来获取相对路径,然后将其与应用程序的基本URL连接起来。以下是获取应用程序缓存URL的示例代码:
from dash import Dash, htmlfrom dash_clientside import clientsideapp = Dash(__name__)app.layout = html.Div([html.Button('Click me', id='button'),html.Div(id='output')])@app.callback(clientside.callback("""function(pathname) {return pathname}""",Output('output', 'children'),[Input('button', 'n_clicks')],prevent_initial_call=True))def update_output(n_clicks):if n_clicks:pathname = app.get_relative_path()cache_url = app.config.requests_pathname_prefix + pathnamereturn cache_urlif __name__ == '__main__':app.run_server(debug=True)
在这个例子中,我们设置了一个按钮,当按钮被点击时,会触发一个回调函数update_output
,该函数获取当前页面的相对路径,并连接到应用程序的基本URL上,最终返回一个缓存URL。您可以根据需要修改这段代码,以适应您的具体需求。