简体   繁体   English

Highchart + Plotly dash 按下按钮前的图表显示

[英]Highchart + Plotly dash Graph displaying before pressing the button

I have embedded plotly dash with highchart.我已经嵌入了带有高图的 plotly 破折号。 My requirement is when I press the Apply button the graph should be displayed.我的要求是当我按下应用按钮时应该显示图表。 But when I run the code itself the graph is displaying.但是当我运行代码本身时,图表正在显示。

import dash
import dash_alternative_viz as dav
import dash_html_components as html
from dash.dependencies import Input, Output
import random

external_scripts = [
    "https://code.highcharts.com/highcharts.js",
    "http://code.highcharts.com/highcharts-more.js",
    "http://code.highcharts.com/maps/modules/map.js",
    "http://code.highcharts.com/maps/modules/data.js",
    "http://www.highcharts.com/samples/data/maps/world.js",
    "https://code.highcharts.com/modules/draggable-points.js"

]
app = dash.Dash(__name__,external_scripts=external_scripts)

app.layout = html.Div([
  html.Button(id="my_button", children="Apply!"),
  dav.HighChart(id="my_highchart")
])

@app.callback(
  Output("my_highchart", "options"), [Input("my_button", "n_clicks")])
  
def random_chart(n_clicks):

  return {
      'title': { 'text': 'Highcharts draggable demo' },
      'series': [{
        'data': [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4,30.9, 41.5, 189, 162.2, 90.0, 45.0, 105.6, 136.5, 389.4, 500.1, 25.6, 69.4],
        'color':'white',
        'marker': {
                'fillColor': 'blue',
                  },
        'cursor': 'move',
          'dragDrop': {
            'draggableX': False,
            'draggableY': True
               }
    }]
  }
  
if __name__ == "__main__":
   app.run_server( port = 8052, debug=True)

Im not sure what could be the issue, can someone help me?我不确定可能是什么问题,有人可以帮助我吗?

Thanks, Meera谢谢,米拉

Per default, all callbacks are executed on initialization in Dash.默认情况下,所有回调都在 Dash 中初始化时执行。 You can bypass this behavior for all callbacks via the prevent_initial_callbacks keyword argument of the Dash object,您可以通过Dash object 的prevent_initial_callbacks关键字参数为所有回调绕过此行为,

app = Dash(..., prevent_initial_callbacks=True)

or on a per callback basis via the prevent_initial_call keyword argument of the callback decorator,或通过回调装饰器的prevent_initial_call关键字参数基于每个回调,

@app.callback(Output(...), Input(...)], prevent_initial_call=True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM