I am curious whether we can render plotly html from plotly objects.
So I have an object <plotting_file.PlotFunctions object at 0x7f57f763bf98>, here plotting_file is my file name and PlotFunctions is my class name. In one of the methods under this class say method1(), I return an object of plotly like this,
Now I am rendering this html_plot in flask but unfortunately I cannot. When I zeroed down little bit, I found that html_plot is this value <plotting_file.PlotFunctions object at 0x7f57f763bf98> but now the file.
Kindly guide me to attain this. I need that object to be rendered as a HTML file.
when you call plotly.offline.plot with output_type='file' (which is the default) then the function will write out a file, and it wonβt return the html contents as a string. If you want a string version of the HTML you have two options
Open the file after itβs written out with something like:
...
html_plot = py.plot(plot_func, filename='./static/plotted_file.html', auto_open=False)
with open('./static/plotted_file.html', 'r') as f:
html = f.read()
return html
Ask plotly.offline.plot to return an html <div> element as a string with something like:
In this case you would need to insert the div in a full HTML page somewhere else.
Also, if you havenβt already considered it, Iβd recommend taking a look at Dash (https://dash.plot.ly/) as a way to build flask apps with plotly visualizations using only Python.