我编写了一个基本的绘图破折号应用程序,它从 csv 中提取数据并将其显示在图表上。然后,您可以在应用程序上切换值并更新图表。
但是,当我向 csv 添加新数据(每天一次)时,应用程序不会在刷新页面时更新数据。
解决方法通常是将您定义app.layout为一个函数,如此处所述(向下滚动到页面加载时的更新)。您将在下面的代码中看到我已经做到了这一点。
这是我的代码:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import numpy as np
import pandas as pd
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
path = 'https://raw.githubusercontent.com/tbuckworth/Public/master/CSVTest.csv'
df = pd.read_csv(path)
df2 = df[(df.Map==df.Map)]
def layout_function():
df = pd.read_csv(path)
df2 = df[(df.Map==df.Map)]
available_strats = np.append('ALL',pd.unique(df2.Map.sort_values()))
classes1 = pd.unique(df2["class"].sort_values())
metrics1 = pd.unique(df2.metric.sort_values())
return html.Div([
html.Div([
dcc.Dropdown(
id="Strategy",
options=[{"label":i,"value":i} for i in available_strats],
value=list(available_strats[0:1]),
multi=True …Run Code Online (Sandbox Code Playgroud) 我正在尝试dash使用 Apache2 服务器和 来服务 (python3.8.2) 应用程序mod_wsgi,但应用程序停止在“正在加载...”屏幕上。服务器为 dash 的每个 .js 脚本返回 404。我在使用 dash 的内置本地服务器时没有遇到任何问题...但我并不想在本地提供此服务。
我希望得到一些关于我哪里出错以及如何启动和运行这个特定应用程序的建议。
使用我的设置,我可以提供一个简单的 python“hello world”和一个简单的 Flask 应用程序。然而,当创建一个简单的“破折号”应用程序时......
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (polyfill@7.v1_6_0m1598005008.8.7.min.js, line 0)
... followed by 12 more similar error messages...
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (dash_renderer.v1_6_0m1598005008.min.js, line 0)
[Error] ReferenceError: Can't find variable: DashRenderer
Global Code (hazcurves:28:103)
Run Code Online (Sandbox Code Playgroud)
我的 apache 访问日志显示了一系列收到 …
我正在创建一个仪表板,我想使用这个交互式地图
嵌入代码:
<iframe height="1043px" width="100%" src="https://www.ons.gov.uk/visualisations/dvc914/map/index.html"></iframe>
现在我不知道那么多 HTML,但这就是我到目前为止所知道的。我知道布局是错误的,但我已经被困了很长一段时间了,有人能指出我正确的方向吗?非常感谢!
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import pandas as pd
from dash.dependencies import Input, Output
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
#H1 = biggest heading, Div = a box containhg info
app.layout = html.Div(children=[
html.H1(children='Hello Dash'),
html.Div(children='''
Dash: A web application framework for Python.
'''),
dcc.Graph(
id='example-graph',
figure=fig
<iframe height="1067px" width="100%" src="https://www.ons.gov.uk/visualisations/dvc914/map/index.html"></iframe>
)
])
if __name__ == '__main__':
app.run_server(debug=True,port=8049,host='127.0.0.1')
Run Code Online (Sandbox Code Playgroud) 如何使用 Python 为在网络服务器上运行的 DASH 应用程序启用 HTTPS?
我已经有 SSL 证书(.key 和 .crt)
我有一个 3D 散点图,我想更新图形的数据(移动滑块时)而不更改 3D 视图。
即使使用此解决方案,3D 视图也会重置:
@app.callback(Output('graph', 'figure'),
Input('slider', 'value'),
State('graph', 'figure'))
def update_fig(value, figure):
if value is not None:
data = new_data(value)
figure['data'][0]['x'] = data['x']
figure['data'][0]['y'] = data['y']
figure['data'][0]['z'] = data['z']
return figure
else:
return figure
Run Code Online (Sandbox Code Playgroud)
是否可以只更新点的坐标?
我创建了一个 dash 应用程序来显示另一个代码正在收集的信息,我想使用 Python 中的 asyncio 模块同时运行它们。
我的代码使用异步函数,而 Dash 应用程序(基于 Flask)在服务时阻止其他任何内容执行。
我不确定这是否需要打开更多线程。
这是我当前的代码,仅运行主协程。
async def main():
some code here...
while True:
try:
await client.handle_message()
except ConnectionClosedError as error:
logger.error(error)
for strategy in strategies:
await asyncio.create_task(...)
some code here...
async def run_dashboard():
app = create_app()
app.run_server('0.0.0.0', 5000, debug=False)
if __name__ == '__main__':
some code here...
# Currently just runs the main coroutine
asyncio.run(main())
Run Code Online (Sandbox Code Playgroud)
如何同时运行 main 和 run_dashboard?
我正在开发一个 Plotly Dash 项目,该项目有很多经过过滤、切片和切块的分区统计图。这些是相当昂贵的计算,会减慢一切速度,所以我认为作为一个很好的接触,我可以在地图周围添加一个 dcc.loading 包装器,至少让用户知道它正在加载,而不是我的仪表板出现滞后的外观。
我遇到的问题是,地图每次更改后都会出现加载图标。即使是不到 1 秒的快速更改,也会出现加载图标。我的挑战是我仍然想使用 dcc.loading 包装器,但让它仅显示在地图的初始加载上。
我正在 Plotly 社区网站上阅读这个解决相同问题的博客,但没有人能够提出解决方案: https: //community.plotly.com/t/loading-states-and-loading-component /19650/35。此外,我正在尝试使用 Dash 帮助页面中的“PreventUpdate”参数: https: //dash.plotly.com/advanced-callbacks,但仍然找不到解决方案。
谁能帮我指出正确的方向?
这是一些示例代码:
import pandas as pd
import dash
from urllib.request import urlopen
import json
import plotly.express as px
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
#from dash.exceptions import PreventUpdate
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
counties = json.load(response)
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
dtype={"fips": str})
fips_choices = df['fips'].sort_values().unique()
app = dash.Dash(__name__)
server = app.server
app.layout …Run Code Online (Sandbox Code Playgroud) 我最近启动了一个 Dash 应用程序,它显示我通过 HTML.iFrame 显示的预先注册的 HTML 文件:
html.Iframe(id = 'my-output', src = "assets/ABCD.html",
style={"height": "495px", "width": "100%",})
Run Code Online (Sandbox Code Playgroud)
我有一个函数/应用程序回调,如下所示:
@app.callback(
Output(component_id='my-output', component_property='children'),
Input(component_id='my-input', component_property='value'),
)
def update_output_div(input_value):
return XYZ
Run Code Online (Sandbox Code Playgroud)
现在我需要在 src 中输出该输出值,如下所示
html.Iframe(id = 'my-output', src = "assets/XYZ.html",
style={"height": "495px", "width": "100%",})
Run Code Online (Sandbox Code Playgroud)
但我不知道如何取回该输出值并更改我的 src 参数。
所以我正在研究 Dash Plotly。网页应该有一个文本框和一个按钮。这个想法是,当我写下图像名称然后选择按钮时,它将显示本地目录中的图像。
我试图将整个工作分为两部分。
首先,我有这段代码,它会显示您在文本框中写入的内容,然后单击按钮。代码:
# -*- coding: utf-8 -*-
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import os
from PIL import Image
import numpy as np
import plotly.express as px
os.chdir(os.path.dirname(os.path.abspath(__file__)))
external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"]
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div(
[
html.I("Try typing the image name in input and observe it"),
html.Br(),
dcc.Input(id="input", type="text", placeholder=""),
html.Div(id="output"),
]
)
@app.callback(
Output("output", "children"),
Input("input", "value")
)
def update_output(input):
return u'Input {}'.format(input)
if …Run Code Online (Sandbox Code Playgroud) 当尝试使用以下代码生成图形时
@app.callback(
[
Output("selected-plot", "figure")
],
[
Input("submit-selected-plotting", "n_clicks"),
State("table", "data")
],
)
def plot(button_clicked, data)
fig = go.Scatter(x=data["index"],
y=data["result"],
mode='lines',
name='result')
return fig
Run Code Online (Sandbox Code Playgroud)
和
dbc.Col(
[
dcc.Graph(id='selected-plot')
],
width=6,
)
Run Code Online (Sandbox Code Playgroud)
我收到一个奇怪的错误,应用程序期待不同的对象:
dash._grouping.SchemaTypeValidationError:架构:[<Output
selected-plots.figure>] 路径:() 预期类型:(<class 'tuple'>,<class 'list'>) 收到类型 <class 'plotly.graph_objs._scatter.Scatter' 的值>: 分散({...})
我已经尝试了一切,但似乎无法解决这个错误。感谢您提前提出任何建议!
plotly-dash ×10
python ×9
html ×3
iframe ×2
plotly ×2
apache ×1
choropleth ×1
concurrency ×1
dashboard ×1
data-science ×1
exception ×1
flask ×1
https ×1
loading ×1