在破折号中加载带有预选值(例如 boxSelect)的 plotly modebar

Load plotly modebar with preselected value (e.g. boxSelect) in dash

我正在 dash 中创建一个绘图图,并尝试使用 boxSelect 的预选操作值创建模式栏。图表加载时,模式栏中没有预选值。

这是我的代码:

dcc.Graph(
  id='scatter',
  className="chart-graph",
  config={
    "modeBarButtonsToRemove": ['toImage', 'zoom2d', 'zoomIn', 'zoomOut','autoScale2d','toggleSpikelines','hoverCompareCartesian', 'hoverClosestCartesian'],
    # This is the line of code I'm hoping initializes things, but it does not work...
    "select2d": True,
  },
)

知道了!配置layout时,添加以下参数:

layout = go.Layout(
  # ...
  clickmode='event+select',
  dragmode = 'lasso',
)

Reference documentation.