Hello,
I am very new to bokeh and webapplication stuff. I am Trying to create a simple python script with bokeh that is supposed to spit out a standalone HTML file, so that it runs without any server/ “bokeh serve”, etc. in the background. That HTML file should simply load a .csv file using the FileInput widget and then plots it as a line plot. It sounded simple for me, but for some reason the HTML doesn’t plot the file… Here is the code:
from bokeh.plotting import save, show, output_file, figure
from bokeh.models import FileInput, ColumnDataSource
from bokeh.layouts import column
import base64
import io
import pandas as pd
from math import pi
def loadData(attr, old, new):
decoded = base64.b64decode(new) #file upload encodes file in bas64 --> need to decode it
fil = io.BytesIO(decoded)
df = pd.read_csv(fil, header=None, names=['Date', 'HH']) #read in csv file with no header and declare header 'Date' and 'HH'
df['Date'] = pd.to_datetime(df['Date'], format='%Y-%m-%d %H:%M:%S') #converting Str to date Type
plt.line(df['Date'], df['HH'])
df = pd.DataFrame()
src = ColumnDataSource(df)
output_file('SpitItOut.html')
file_input = FileInput(accept='.csv', width=200)
file_input.on_change('value', loadData)
#Plotting
plt = figure(
title="PLOT IT, DAMN IT !!!!!!!",
x_axis_label="Date",
x_axis_type='datetime', # sets date as axis type (simple layout format)
y_axis_label="Hydraulic Head [m]"
)
plt.xaxis.major_label_orientation = pi/4 #shows x axis label with 45 degree angle
bundle = column(file_input, plt)
#Output
show(bundle)
save(bundle, output_file)
Can you please tell me if it is even possible, what i try to do? If yes, what am I doing wrong? I
Thank you very much in advance.
all the Best