标签: plotly-dash

从 Dash 中的 onclick 触发 javascript

我正在运行一个 Python Dash 应用程序,其中有几个回调和一个漂亮的图表。接下来我需要的是一个按钮,用于将一些结果以 Excel 格式复制到剪贴板(非常具体,是的)。我想我需要实现一个由按钮 onclick触发的javascript函数,但我不知道如何让Python应用程序调用javascript。有人可以帮我解决这个问题吗?:)

像这样的东西:

function copy_to_cliboard() {
  var copyText = document.getElementById("text_input");

  copyText.select();
  copyText.setSelectionRange(0, 99999);

  document.execCommand("copy");

  alert("Copied the text: " + copyText.value);
}
Run Code Online (Sandbox Code Playgroud)

多谢!

javascript python-3.x plotly-dash

6
推荐指数
1
解决办法
6113
查看次数

如何在只有 1 个中心节点的旭日图中正确使用“percentParent”?

因此,我正在尝试构建一个 Plotly sunburst 图,用于显示percentParent图中的每个元素。这适用于所有元素,除了当我只有一个中央节点/环/其他选项时(请参见下面的示例)

在此输入图像描述

由于中心节点显然没有父节点,因此它似乎会出错并显示percentParent来自texttemplate字段的括号内的调用。但是,如果有 2 个(或更多)中心节点,它会自动计算每个中心节点占两个节点总和的百分比。

我的问题是:当我只有 1 个中心节点时,如何仅为中心节点隐藏此字段或使其正确显示“100%”?

示例代码:

import pandas as pd
import plotly.graph_objects as go

df = pd.DataFrame({'node_names': ['Center', 'Yes', 'No'],
                   'node_parent': ['', 'Center', 'Center'],
                   'node_labels': ['Center', 'Center_Yes', 'Center_No'],
                   'node_counts': [1000, 701, 299]})


fig = go.Figure(
       data=go.Sunburst(
        ids=df["node_names"],
        labels=df["node_labels"], 
        parents=df["node_parent"],
        values=df["node_counts"],
        branchvalues="total",
        texttemplate = ('%{label}<br>%{percentParent:.1%}'),
    ),
)

fig.show()
Run Code Online (Sandbox Code Playgroud)

python plotly sunburst-diagram plotly-dash

6
推荐指数
1
解决办法
2263
查看次数

运行 docker 时无法将“app.server”解析为属性名称或函数调用

我正在尝试从 docker 运行我的应用程序,但我收到了来自docker logs破折号的错误消息。我搜索了很多但找不到任何东西。请帮忙!

docker logs来自破折号图像的日志消息

[2020-08-22 06:44:32 +0000] [1] [INFO] Starting gunicorn 20.0.4
[2020-08-22 06:44:32 +0000] [1] [INFO] Listening at: http://0.0.0.0:8050 (1)
[2020-08-22 06:44:32 +0000] [1] [INFO] Using worker: sync
[2020-08-22 06:44:32 +0000] [8] [INFO] Booting worker with pid: 8
Failed to parse 'app.server' as an attribute name or function call.
[2020-08-22 06:44:33 +0000] [8] [INFO] Worker exiting (pid: 8)
[2020-08-22 06:44:33 +0000] [1] [INFO] Shutting down: Master
[2020-08-22 06:44:33 +0000] [1] [INFO] Reason: App failed …
Run Code Online (Sandbox Code Playgroud)

python docker dockerfile docker-compose plotly-dash

6
推荐指数
2
解决办法
6827
查看次数

Plotly 图例在手机上无法缩放

我正在使用 Dash 绘制一个情节。当我在桌面上查看它时,看起来不错 桌面

但是当我在手机上查看它时,图例位置与图表重叠。 电话

我的传奇是使用设置的

legend=dict(
    bgcolor='rgba(0,0,0,0)',
    orientation="h",
    yanchor="bottom",
    y=-0.15,
    xanchor="left",
    x=0
)
Run Code Online (Sandbox Code Playgroud)

如何修复图例?额外问题,如何修复模式栏?

python plotly plotly-dash

6
推荐指数
1
解决办法
515
查看次数

如何在plotly中将时间线图与散点图结合起来

我有一个数据框df,其中包含随时间变化的值(过程数据)。我有一个数据框ef,其中包含具有开始时间和结束时间的事件(警报)。我想以一种美观的方式将它们组合在一个情节中。

"""
df==
+---------------------+------------+------------+------------+
|                     |   processA |   processB |   processC |
|---------------------+------------+------------+------------|
| 2020-01-01 00:00:00 |    101.764 |   20.0079  |   0.978738 |
| 2020-01-01 00:01:00 |    102.241 |   93.3779  |  -0.977278 |
| 2020-01-01 00:02:00 |    100.95  |   -7.56786 |  -0.103219 |
| 2020-01-01 00:03:00 |    100.411 |    7.20218 |   1.45427  |
| 2020-01-01 00:04:00 |    100.761 |    6.08375 |   0.443863 |
+---------------------+------------+------------+------------+

ef==
+----+-----------------------------------------+---------------------+---------------------+----------+
|    | alm                                     | Start               | Finish              | almid    | …
Run Code Online (Sandbox Code Playgroud)

python pandas plotly plotly-dash

6
推荐指数
1
解决办法
1490
查看次数

有人尝试过使用 Dash Plotly 制作移动应用程序吗?

有人尝试过使用 Dash 制作移动应用吗?

\n

我发现在手机上浏览 Dash 页面非常有用,但我不想每次都输入 URL 并登录。

\n

而如果它\xe2\x80\x99是一个移动应用程序,无论是嵌入式还是本机,都有更多可以实现的功能。

\n

mobile plotly plotly-dash

6
推荐指数
1
解决办法
5103
查看次数

python中的点击事件plotly-dash散点图

我想创建两个包含 iframed 虚线图的网页。我想实现第一个图表的点击事件以重定向到另一个页面(包含有关该特定数据的更多信息)

我遵循了指南,但即使我将 ipywidgets、node.js 和plotlywidgets 扩展安装到我正在运行的 python venv 中,我的设置中也不会触发单击事件。上面的示例中有一条注释:

注意:只有当跟踪属于plotly.graph_objs.FigureWidget 的实例并且它显示在ipywidget 上下文中时才会触发回调。使用plot/iplot 显示的图形不会触发回调。

该示例使用的是FigureWidget,我通过将数字传递到dcc.Graph应与 相同的方式来绘制它fig.show()。整个代码看起来像这样

import plotly.graph_objects as go
import numpy as np
np.random.seed(1)

x = np.random.rand(100)
y = np.random.rand(100)

fig = go.FigureWidget([go.Scatter(x=x, y=y, mode='markers')])

scatter = fig.data[0]
colors = ['#a3a7e4'] * 100
scatter.marker.color = colors
scatter.marker.size = [10] * 100
fig.layout.hovermode = 'closest'


# create our callback function
def update_point(trace, points, selector):
    c = list(scatter.marker.color)
    s = list(scatter.marker.size)
    for …
Run Code Online (Sandbox Code Playgroud)

python onclick ipywidgets plotly-dash

6
推荐指数
1
解决办法
7948
查看次数

如何为 Plotly Dash 回调函数编写测试用例?

我正在尝试在页面中为 Dash 回调函数编写一个测试用例,该页面将 2 个数据表的选定行存储到dash_core_components.Store,并通过以下方式确定状态dash.callback_context

示例回调函数在index.py

@app.callback(
    Output('rows-store', 'data'),
    Input('datatable1', 'selected_rows'),
    Input('datatable2', 'selected_rows'),
)
def store_row_selection(row1: list, row2: list) -> dict:
    ctx = dash.callback_context
    if not ctx.triggered:
        return {'row-index-v1': [0], 'row-index-v2': [0]}
    else:
        return {'row-index-v1': row1, 'row-index-v2': row2}
Run Code Online (Sandbox Code Playgroud)

示例测试用例位于test.py

def test_store_row_selection_1(app_datatable):
    r1 = [0]
    r2 = [1]
    result = store_row_selection(r1, r2)

    assert type(result) is dict  
Run Code Online (Sandbox Code Playgroud)

但是,Pytest 在运行时抛出异常,测试回调函数的正确方法是什么以及如何让它工作?

  @wraps(func)
    def add_context(*args, **kwargs):
>       output_spec = kwargs.pop("outputs_list")
E       KeyError: 'outputs_list'
Run Code Online (Sandbox Code Playgroud)

python pytest plotly-dash

6
推荐指数
1
解决办法
2764
查看次数

Python Dash:向 DIV 添加滚动条

我希望将滚动条添加到 Dash 应用程序的侧栏面板 - 请参阅此应用程序作为示例。当内容跑出页面时,我可以让滚动条动态显示,但我似乎可以让主页 div 显示在侧边栏 div 右侧的唯一方法是设置 CSS style "position": "fixed"。但是,即使滚动条可用,该设置也会将内容固定在适当的位置。在此输入图像描述

这是代码:

import dash
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])

# the style arguments for the sidebar. We use position:fixed and a fixed width
SIDEBAR_STYLE = {
    "position": "fixed",
    "top": 0,
    "left": 0,
    "bottom": 0,
    "width": "16rem",
    "padding": "2rem 1rem",
    "background-color": "#f8f9fa",
}

# the styles for the main content position …
Run Code Online (Sandbox Code Playgroud)

python plotly-dash

6
推荐指数
1
解决办法
9324
查看次数

如何通过 url 从 Flask 应用程序向 dash 应用程序发送一些值?Flask 和 dash 应用程序独立运行

我有一个在一端运行的烧瓶应用程序和一个破折号应用程序都单独运行,但我在烧瓶应用程序主页中有一个链接,单击该链接将重定向到破折号应用程序,但我想将一些值(例如当前 user_id)传递给破折号应用程序重定向到 dash 应用程序,然后我想从 URL 读取该值,然后我可以显示它的 dash 主页。

我请求有人可以帮助我,请帮助我。

python integration flask plotly-dash

6
推荐指数
1
解决办法
5104
查看次数