The goal is to stream data into panel and show the current temperature in a Gauge. Panel EChart Gauge
Therefore I am using the callback function for the panel to retrieve a new temperature value and like to update the Gauge as well with the JSCallback function.
I also looked into the following questions on stackoverflow:
Here is the current code:
import time
import panel as pn
import random
random.seed()
def read_temp():
return random.randint(15, 30)
global temperature
temperature = read_temp()
# Stream function
def stream():
temperature = read_temp()
print(temperature)
#how to access the js object?
pn.state.jscallback(args={'gauge': gauge_pane}, value="""
gauge.data.series[0].data[0].value = """+str(temperature))
gauge = {
'tooltip': {
'formatter': '{a} <br/>{b} : {c}°C'
},
'series': [
{
'name': 'Gauge',
'type': 'gauge',
'detail': {'formatter': '{value}°C'},
'data': [{'value': [temperature], 'name': 'Temperature'}]
}
]
};
#Panel
pn.extension('echarts',sizing_mode="stretch_width",template="fast")
ACCENT = "orange"
pn.state.template.param.update(site="Test", title="Introduction to data apps with Panel",
sidebar_width=200, accent_base_color=ACCENT,
header_background=ACCENT, font="Montserrat")
gauge_pane = pn.pane.ECharts(gauge,width=400, height=400).servable()
pn.pane.JPG("logo.jpg", sizing_mode="scale_width", embed=False).servable(area="sidebar")
pn.panel("# Settings").servable(area="sidebar")
# Set up callback with streaming data
pn.state.add_periodic_callback(stream, 500)
May be someone from the panel developers / community has some hints or some example. I mainly like to understand how I can access the JS Objects to be updated in the panel. So maybe JSLink is the right way to do it? If yes how would that work with my little example? - Thank you! :-)