我正在运行一个 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)
多谢!
因此,我正在尝试构建一个 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) 我正在尝试从 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) 我正在使用 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)
如何修复图例?额外问题,如何修复模式栏?
我有一个数据框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) 有人尝试过使用 Dash 制作移动应用吗?
\n我发现在手机上浏览 Dash 页面非常有用,但我不想每次都输入 URL 并登录。
\n而如果它\xe2\x80\x99是一个移动应用程序,无论是嵌入式还是本机,都有更多可以实现的功能。
\n我想创建两个包含 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) 我正在尝试在页面中为 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) 我希望将滚动条添加到 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) 我有一个在一端运行的烧瓶应用程序和一个破折号应用程序都单独运行,但我在烧瓶应用程序主页中有一个链接,单击该链接将重定向到破折号应用程序,但我想将一些值(例如当前 user_id)传递给破折号应用程序重定向到 dash 应用程序,然后我想从 URL 读取该值,然后我可以显示它的 dash 主页。
我请求有人可以帮助我,请帮助我。
plotly-dash ×10
python ×8
plotly ×4
docker ×1
dockerfile ×1
flask ×1
integration ×1
ipywidgets ×1
javascript ×1
mobile ×1
onclick ×1
pandas ×1
pytest ×1
python-3.x ×1