Skip to content

Instantly share code, notes, and snippets.

@jingningzhang1
Last active June 24, 2022 01:12
Show Gist options
  • Save jingningzhang1/d566b319b978b0ed76adab2a7c71f05f to your computer and use it in GitHub Desktop.
Save jingningzhang1/d566b319b978b0ed76adab2a7c71f05f to your computer and use it in GitHub Desktop.
def update_graph(input_value):
## ORM-based SQL Query with dynamic filters in the callback
stmt = select([
sensor_table.columns.MeasurementDateTime,
sensor_table.columns.LongMovingAverage,
sensor_table.columns.SensorLocation
]).where(and_(
sensor_table.columns.SensorMeasurement == input_value
))
## Read data via pandas or just raw Dict/array
## TIPS: Always try to push the filtering/complex logic down to the system where the most data is filtered
## minimize data brought to client
df = pd.read_sql_query(stmt, engine).sort_values(by=['MeasurementDateTime'])
fig_line = px.line(df, x="MeasurementDateTime",
y="LongMoving Average",
color="SensorLocation",
title=f'Sensor Value Moving Averages Over Time for : {input_value}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment