I am a dash noob, was trying to get something very basic running using a server-side event (SSE) server. This data comes from particle cloud, if you are familiar. the data looks like:
event: Pitch
data: {"data":"5.271323","ttl":60,"published_at":"2023-04-30T17:11:50.054Z","coreid":"e00fce68ec56b856e8641198"}
event: Temperature
data: {"data":"24.625000","ttl":60,"published_at":"2023-04-30T17:11:50.055Z","coreid":"e00fce68ec56b856e8641198"}
event: Roll
data: {"data":"2.747430","ttl":60,"published_at":"2023-04-30T17:11:50.055Z","coreid":"e00fce68ec56b856e8641198"}
event: Pitch
data: {"data":"1.407578","ttl":60,"published_at":"2023-04-30T17:11:57.094Z","coreid":"e00fce68ec56b856e8641198"}
I am using the basic example from the EventSource documentation in dash_extensions:
from dash_extensions import EventSource
from dash_extensions.enrich import html, dcc, Output, Input, DashProxy
# Client-side function (for performance) that updates the graph.
update_graph = """function(msg) {
console.log(msg);
if(!msg){console.log("no messages"); return {data: [{y: 0, type: "scatter"}]};} // no data, just return
const data = JSON.parse(msg.data); // read the data
return {data: [{y: data.data, type: "scatter"}]}}; // plot the data
"""
# Create small example app.
app = DashProxy(__name__)
app.layout = html.Div([
EventSource(id="sse", url="https://api.particle.io/v1/devices/events?access_token=1234"),
dcc.Graph(id="graph")
])
app.clientside_callback(update_graph, Output("graph", "figure"), Input("sse", "message"))
if __name__ == "__main__":
app.run_server()
yet, the msg always seems to be blank. it also doesnt seem to be updating each time a new SSE comes in, which is how I thought this would work. (note that the access token in the URL I changed for this post)
Am I doing something incredibly wrong?