我正在使用 Python 中的 Bokeh 库来创建交互式网络图表。我想将这些图表存储在 Google 站点上,以便在我的组织域内轻松访问,但我不知道如何保持实时同步。
图表数据位于 Google 电子表格中。我将该数据导入到 Pandas DataFrame 中,然后在 Bokeh 中创建可视化。我可以获取 html 输出文件并将其复制到 Google 站点中的嵌入小部件中,但这仍然是静态可视化。我希望图表在新数据添加到谷歌表时刷新。这可能吗?这是我的代码相同:
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)
如何触发可视化以运行 Python 脚本,该脚本将在每次页面加载时获取更新的数据?这甚至可能吗?