Skip to content

Instantly share code, notes, and snippets.

@yasasi-abeysinghe
Created July 18, 2023 00:18
import pandas as pd
import hvplot.pandas
import panel as pn
import hvplot.streamz
from streamz import Stream
from streamz.dataframe import DataFrame as sDataFrame
from datetime import date, datetime
data_stream = Stream()
# Run the server and listen for incoming messages
def start_server():
pn.extension('vega')
global data_stream
index = pd.DatetimeIndex([])
weather_example = pd.DataFrame(
{'Temp': [], 'Feels_Like': [], 'Wind_Speed': [], 'UV': [], 'Humidity': [], 'Location': [], 'Timestamp': []},
columns=['Temp', 'Feels_Like', 'Wind_Speed', 'UV', 'Humidity', 'Location', 'Timestamp'],
index=[])
# Define streaming dataframe
sdf = sDataFrame(data_stream, example=weather_example)
line_plot_temp = sdf[['Temp', 'Location', 'Timestamp']].hvplot(
x='Timestamp', y='Temp', xlabel='Timestamp', ylabel='Temperature (F)', by='Location',
width=500, height=255)
today = str(datetime.now().strftime('%A')) + ", " + str(date.today())
# Layout using Template
template = pn.template.FastListTemplate(
title='Real-time Interactive Dashboard for Data in a Distributed System',
sidebar=[pn.pane.Markdown("# Weather Dashboard"),
pn.pane.Markdown("### Visualization of real-time weather data collected from multiple locations."),
pn.pane.PNG('image.png', sizing_mode='scale_both'),
pn.pane.Markdown('<br/><br/><br/>'),
pn.pane.Markdown('### Date:'),
today],
main=[pn.Row(
pn.Column(line_plot_temp)
)],
accent_base_color="#88d8b0",
header_background="#88d8b0",
)
template.show()
start_server()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment