【问题标题】:Is this code using JupyterDash or plotly dash?这段代码是使用 JupyterDash 还是 plotly dash?
【发布时间】: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


【解决方案1】:

您发布的代码使用 JupyterDash应用程序,可从app = JupyterDash(__name__) 行识别。但是,它使用 Dash成分作为应用程序的一部分,因为 JupyterDash(它是由 plotly 开发的,“原始”Dash 也是如此)与 Dash 基本相同,但专为在 Jupyter 笔记本中运行而量身定制。因此,JupyterDash 应用程序可以像 Dash 应用程序一样构建,但会提供额外的功能,以便在 Jupyter 笔记本中获得流畅的用户体验。

更多细节,我建议阅读the announcement of JupyterDash from plotly

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-18
    • 2023-03-29
    • 2017-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多