【发布时间】:2022-10-08 09:00:52
【问题描述】:
下面的代码看起来像是 plotly dash 和 Jupyter dash 的组合,它是通过 jupyter notebook 运行的。有人可以解释为什么 jupyter dash 和 plotly dash 需要一起使用吗?
from jupyter_dash import JupyterDash
from dash import Dash, dcc, html, Input, Output, no_update
import plotly.graph_objects as go
import pandas as pd
app = JupyterDash(__name__)
fig = go.Figure(data=[
go.Scatter(
x=df['x_lv'], #x_px and y_px for pixel data
y=df['y_lv'],
mode='markers',
marker=dict(color=df['color']), showlegend=True
)
])
# turn off native plotly.js hover effects - make sure to use
# hoverinfo="none" rather than "skip" which also halts events.
fig.update_traces(hoverinfo="none", hovertemplate=None)
server = app.server
app.layout = html.Div([
dcc.Graph(id="graph-basic-2", figure=fig, clear_on_unhover=True),
dcc.Tooltip(id="graph-tooltip"), html.Div(id="debug"),
])
@app.callback(
Output("graph-tooltip", "show"),
Output("graph-tooltip", "bbox"),
Output("graph-tooltip", "children"),
Input("graph-basic-2", "hoverData"),
)
def display_hover(hoverData):
if hoverData is None:
return False, no_update, no_update
# demo only shows the first point, but other points may also be available
pt = hoverData["points"][0]
bbox = pt["bbox"]
num = pt["pointNumber"]
app.run_server(mode="inline", host="localhost",port=8052)
【问题讨论】:
-
我不确定您所说的 Plotly Dash 和 Jupyter Dash 是什么意思,但在您提供的代码中,正在使用的服务器是 JupyterDash 以允许在 Jupyter 笔记本中查看 dash 应用程序。至于 Plotly Dash,您只能使用 Plotly Dash 构建组件,因此即使您正在运行 JupyterDash 服务器,您仍然需要使用 Plotly Dash 为其构建组件。
标签: jupyter plotly-dash