Reputation: 39
I am using the Bokeh library in Python to create interactive web charts. I want to store these charts on a Google Site so it is easily accessible within my organization's domain, but I cannot figure out how to keep it live-synced.
The data for the charts is in a Google Spreadsheet. I import that data into a Pandas DataFrame and then create the visualization in Bokeh. I can get the html output file and copy that into an Embed widget in the Google Site, but that remains a static visualization. I want the chart to refresh as new data is added to the google sheet. Is this possible? Here is the same of my code:
from bokeh.plotting import figure
from bokeh.io import output_file, show, save
from bokeh.resources import CDN
from bokeh.embed import file_html
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import pandas as pd
#Connect to Google Sheet and get data
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'WUSD Dashboard.json', scope) # Your json file here
gc = gspread.authorize(credentials)
wks = gc.open("Walk Through Data (Responses)").sheet1
data = wks.get_all_values()
headers = data.pop(0)
#Make dataframe from Google Data
#Change data types for numeric columns to numeric data type (they import as a string)
df = pd.DataFrame(data, columns=headers)
df["Engagement (x)"]=pd.to_numeric(df["Engagement (x)"])
df["Evidence of learning (y)"] = pd.to_numeric(df["Evidence of learning (y)"])
cat = df["Site"]
x = df["Engagement (x)"]
y = df["Evidence of learning (y)"]
output_file("Scatter.html")
f = figure()
f.scatter(x,y)
save(f)
How can I trigger the visualization to run the Python Script that will fetch the updated data every time the page loads? Is this even possible?
Upvotes: 0
Views: 586
Reputation: 21
This is a bit late but Google Collab might be a viable option:
https://colab.research.google.com/
You can create a python "notebook" that will run your code on-demand. This can be stored in Google Drive and anyone can access and run it on Google Collab at any time
Upvotes: 2