hamedk
December 31, 2020, 3:35pm
1
I have a script that produces CSV files every 5 minutes and dash script reads these CSV files. I want to update the dash script when another script runs. What’s the solution? without using the Interval
method.
Emil
December 31, 2020, 3:45pm
2
You can use the Interval
component to update the web page regularly (e.g. once per minute), or you could use the WebSocket
component from dash-extensions
to push the changes, when they are ready.
1 Like
hamedk
December 31, 2020, 4:43pm
3
Thanks. I don’t want to use the Interval
. Can I send a command from another script to dash script for updating? could you please explain more?
Emil
December 31, 2020, 5:51pm
4
Here is some inspiration,
import dash_html_components as html
from dash import Dash
from dash.dependencies import Input, Output
from dash_extensions.websockets import SocketPool, run_server
from dash_extensions import WebSocket
# Create example app.
app = Dash(prevent_initial_callbacks=True)
socket_pool = SocketPool(app)
app.layout = html.Div([html.Div(id="msg"), WebSocket(id="ws")])
# Update div using websocket.
app.clientside_callback("function(msg){return \"Response from websocket: \" + msg.data;}",
Output("msg", "children"), [Input("ws", "message")])
# End point to send message to current session.
@app.server.route("/send/<message>")
def send_message(message):
socket_pool.send(message)
This file has been truncated. show original
For your use case, i guess you would run the code to collect the data, and then broadcast a message whenever new data arrives.
@Emil The original code you shared is not available anymore - could you share it again?