0

as a very simple example when I want to export a visualisation to a html in bokeh i'd do something like this:

#importing bokeh
from bokeh.plotting import figure
from bokeh.io import output_file, show

#data prep
x=[1,2,3,4,5]
y=[6,7,8,9,10]

#prep output file
output_file('line.html')

#create a figure object
f=figure()

#create a line plot
f.square(x,y)

show(f)

which seems to work fine.

however when working with a visualisation like a histogram and when working with pandas_bokeh i cant get it to export as a html. for example:

import pandas as pd
import pandas_bokeh
pandas_bokeh.output_notebook()

df['any random numerical column'].plot_bokeh(kind='hist',)
output_file('hist.html')

anyone know how i can get this to work?

my second question is, is how would I export a viz if I was using holoviews? as in how can the code be altered here: http://holoviews.org/gallery/demos/bokeh/boxplot_chart.html for it to be done?

any light shed on these 2 questions would be greatly appreciated and please explain as simply as possible as this is all fairly new to me. thank you

3
  • As a kind of a workaround you can run this code in the Jupyter Notebook and export this notebook as HTML. Commented Apr 20, 2022 at 9:29
  • I have been using Jupyter to run the code, however its not exporting as a html. any help? Commented Apr 20, 2022 at 9:32
  • And how is it exporting? Is there an error? Are you using File -> Download as -> HTML ? Commented Apr 20, 2022 at 10:13

1 Answer 1

1

To quote form the documentation for output_file():

output_file() creates an output to a file when show() is called.

Another option is to call save() after output_file() to create the HTML-File.

Example for pandas-bokeh

import pandas as pd
import pandas_bokeh
from bokeh.io import output_file, save
pandas_bokeh.output_notebook()

df = pd.DataFrame({'x':[1,2,3,4,5], 'y':[3,4,2,1,3]})
p = df.plot_bokeh()

output_file('lines.html')
save(p)

Since show() is called inside pandas-bokeh anyway an even shorter example to generate the same figure is:

import pandas as pd
import pandas_bokeh
from bokeh.io import output_file
pandas_bokeh.output_notebook()

output_file('lines.html')
df = pd.DataFrame({'x':[1,2,3,4,5], 'y':[3,4,2,1,3]})
df.plot_bokeh()

Holoviews

For holoviews there exists the method `hv.save() to genreate a html, too.

But you can also get the bokeh object by calling p = hv.render(fig) and do the same with the save from the pandas-bokeh example.

I didn't try it, but it is also possible that holoviews internally calls show() so the second example cloud also work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.