我对 python 编码很陌生。使用 Dash - Plotly,我将传感器数据绘制到 GEO 地图上,地图下方是直方图,显示每小时传感器观测的频率。有三个下拉条目可根据日历中的日期选择器、传感器选择器和小时选择器过滤数据。
Dash-Plotly 的示例代码最初采用其自己的示例 CSV 文件作为上图(位置:纽约)。我使用了自己的 CSV,并确保根据示例 CSV 的格式进行更改(位置:非洲)。这导致以下数据格式(两行示例):
**Date/Time Lat Lon**
2019-03-25 04:00:00 -10,80948998827914 20,19160777427344
2019-03-25 04:05:00 -10,798684405083584 20,16288145431259
Run Code Online (Sandbox Code Playgroud)
我的问题:一切似乎都正常。除非我选择本月 7 日之后的任何日期。然后我得到了三个错误,我一生都不明白为什么,因为除了 CSV 之外没有任何改变:
编辑 1: 作为示例用例:在我的 CSV 中,我有日期“2019-03-23”的传感器观察结果。因此,当我在网页上选择日期:2019 年 3 月 23 日时,出现以下错误:
- Callback error updating total-rides.children - IndexError: list index out of range
File "/Frontend/app.py", line 262, in update_total_rides
len(totalList[date_picked.month - 4][date_picked.day - 1])
- Callback error updating histogram.figure - IndexError: list index out of range
File "/Frontend/app.py", …Run Code Online (Sandbox Code Playgroud) 目标:我以前从未这样做过,并且是 Python 的新手。我想在按下按钮时随时运行 python 脚本。
问题:有人可以指出如何解决这个问题吗?
我的代码:
**Button HTML**
# Layout of Dash App HTML
app.layout = html.Div(
children=[
html.Div(
html.Button('Detect', id='button'),
html.Div(id='output-container-button',
children='Hit the button to update.')
],
),
],
)
@app.callback(
dash.dependencies.Output('output-container-button', 'children'),
[dash.dependencies.Input('button')])
def run_script_onClick():
return os.system('python /Users/ME/Desktop/DSP_Frontend/Pipeline/Pipeline_Dynamic.py')
Run Code Online (Sandbox Code Playgroud)
目前这给出了错误:
Traceback (most recent call last):
File "app.py", line 592, in <module>
[dash.dependencies.Input('button')])
TypeError: __init__() missing 1 required positional argument: 'component_property'
Run Code Online (Sandbox Code Playgroud)
编辑:
我认为解决方案可能是将 some_argument 添加到 run_script_onClick 中:
def run_script_onClick(some_argument):
return os.system('python /Users/ME/Desktop/DSP_Frontend/Pipeline/Pipeline_Dynamic.py')
Run Code Online (Sandbox Code Playgroud)
我目前正在浏览此列表以查找合适的 item() …