I want to read CSV regularly and update the value calculated by pandas, but it doesn’t update well. Help me.
import os
import json
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import plotly.graph_objs as go
import dash_table
import numpy as np
import pandas as pd
from datetime import datetime
from dash.dependencies import Input, Output, State
from dash import Dash, callback_context, no_update
import datetime as dt
import time
import dash_bootstrap_components as dbc
external_stylesheets = ["https://codepen.io/ogawahideyuki/pen/LYVzaae.css"]
app = dash.Dash(
__name__,
external_stylesheets=external_stylesheets,
meta_tags=[
{"name": "viewport", "content": "width=device-width, initial-scale=1.0"}
],
)
app.config.suppress_callback_exceptions = True
cfg = dict()
appdata_csv = dt.datetime.now()
appDataPath = appdata_csv.strftime('%Y_%m_%d')
appDataPath
cfg['app_data_dir'] = appDataPath
# READ DATA
# ============================================
# データを読み込む
# ============================================
today_csv = pd.read_csv('src/2021_03_19.csv',
index_col=0,
parse_dates=True
)
app.layout = html.Div([
html.Div(
[
html.H2(
f"工程可視化ダッシュボード",
style={"display": "inline-block", "marginRight": 40},
),
html.P(
"最終更新日",
style={"display": "inline-block"},
className="update_date",
),
html.A(html.Button("分析", className='three columns'),
href="http://127.0.0.1:8050/hands-on-02", target="_blank",
style={"margin-left": "3%"},
# style={"display": "block"},
),
],
style={"width": "100%", "backgroundColor": "#000000", "borderRadius": 10,
"padding": "1%", "vertical-align": "middle"},
),
dcc.Interval(id="interval", interval=10000),
dcc.Graph(id="output"),
dcc.Markdown(
"""
データ元 :
"""
),
html.A(
"生産技術データベース",
href="\\192.168.4.84",
target="_blank",
# style={"display": "inline-block"},
),
])
@app.callback(Output("output", "figure"), [Input("interval", "n_intervals")])
def display_time(n):
today_csv = pd.read_csv('src/2021_03_19.csv',
index_col=0,
parse_dates=True
)
today_1hour = today_csv.sort_values(['data', 'date'])
today_1hour12 =today_1hour.query(' location in (1, 2)').copy()
today_1hour12["diff_time"] = today_1hour12.index.to_series().diff().map(lambda x: x.total_seconds())
today_1hour12 = today_1hour12.query('location == 2')
today_1hour12 = today_1hour12[(today_1hour12['diff_time'] < 200.0) & (today_1hour12['diff_time'] > 0)]
today_1hour12.reset_index(drop=False, inplace=True)
tidy_2_1hours = today_1hour12[today_1hour12['date'] > dt.datetime.now()- dt.timedelta(minutes=1000)]
tidy_2_1hours = tidy_2_1hours.replace({'location': {2: '員数管理'}})
tidy_2_1hours_n = tidy_2_1hours["diff_time"].count()
fig=go.Box(
x= tidy_2_1hours["location"],
y=tidy_2_1hours["diff_time"],
name="員数管理"+ f"(n={tidy_2_1hours_n})",
jitter=0.8,
pointpos=-0.8,
text=tidy_2_1hours["date"],
boxpoints='all', # represent all points
marker_color='rgba(93, 164, 214, 0.5)',
line_color='rgba(93, 164, 214, 0.5)'
)
return fig
if __name__ == "__main__":
app.run_server(debug=True)
(This error originated from the built-in JavaScript code that runs Dash apps. Click to see the full stack trace or open your browser’s console.)
Error: Failed component prop type: Invalid component prop figure
key boxpoints
supplied to Graph.
Bad object: {
“boxpoints”: “all”,
“jitter”: 0.8,
“name”: “員数管理(n=0)”,
“pointpos”: -0.8,
“text”: ,
“x”: ,
“y”: ,
“type”: “box”,
“marker”: {
"color": "rgba(93, 164, 214, 0.5)"
},
“line”: {
"color": "rgba(93, 164, 214, 0.5)"
}
}
Valid keys: [
“data”,
“layout”,
“frames”
]
at propTypeErrorHandler (http://127.0.0.1:8050/_dash-component-suites/dash_renderer/dash_renderer.v1_9_0m1611094913.dev.js:98515:9)
at CheckedComponent (http://127.0.0.1:8050/_dash-component-suites/dash_renderer/dash_renderer.v1_9_0m1611094913.dev.js:92763:77)
at renderWithHooks (http://127.0.0.1:8050/_dash-component-suites/dash_renderer/react-dom@16.v1_9_0m1611094913.14.0.js:14938:20)
at updateFunctionComponent (http://127.0.0.1:8050/_dash-component-suites/dash_renderer/react-dom@16.v1_9_0m1611094913.14.0.js:17169:22)
at beginWork (http://127.0.0.1:8050/_dash-component-suites/dash_renderer/react-dom@16.v1_9_0m1611094913.14.0.js:18745:18)
at HTMLUnknownElement.callCallback (http://127.0.0.1:8050/_dash-component-suites/dash_renderer/react-dom@16.v1_9_0m1611094913.14.0.js:182:16)
at Object.invokeGuardedCallbackDev (http://127.0.0.1:8050/_dash-component-suites/dash_renderer/react-dom@16.v1_9_0m1611094913.14.0.js:231:18)
at invokeGuardedCallback (http://127.0.0.1:8050/_dash-component-suites/dash_renderer/react-dom@16.v1_9_0m1611094913.14.0.js:286:33)
at beginWork$1 (http://127.0.0.1:8050/_dash-component-suites/dash_renderer/react-dom@16.v1_9_0m1611094913.14.0.js:23338:9)
at performUnitOfWork (http://127.0.0.1:8050/_dash-component-suites/dash_renderer/react-dom@16.v1_9_0m1611094913.14.0.js:22292:14)