Generate HTML with plotly graphs and a navbar - python

I am running a Python pipeline that generates some data files. As a last step of the pipeline, I want to generate a HTML file containing nicely styled graphs representing that data with plotly and a navbar at the top (I will probably have 2 tabs, each one containing different set of charts). This sounds like hard to do with plotly only. How can I achieve this? Should I make an html file with some styling, then just embed the plotly graphs in it? Or should I try to do it solely using plotly?

I did some something similar writing the html (and nav elements) from python and then embedding the charts using the to_html method:
fig.to_html(full_html=False, include_plotlyjs=True)

Related

Exporting functional Plotly sunburst plot

Does anyone know how I can export a plotly sunburst plot as a standalone file which can keep all the functionalities, like annotation while hovering and expansion by click?
Visualizing a hierarchical data with plotly.sunburst in python is a beautiful and beneficial way of presenting it in the best order, while you are able to hover the values to see the annotation, click on each parent section to collapse and expand the child values, etc.. But to present the visualized data (plot) independently without having to open the Python notebook, needs the plot to be saved and exported in a standalone file format that allows keeping every functionality available.
Does anyone know how to do this? and what file format can give this luxury to us?
Thanks
Saving to an HTML file will do the trick:
doc

How to export plotly plots, tabs and images into a single html

I would like to know if there is a way to export multiple plotly plots, tabs and images into a single HTML file.
In detail the problem is this. I want to create a standalone .exe file with python able to plot several graphs and images, given some input files containing the data; writing code with PySimpleGUI for the GUI.
But once the several interactive graphs, tabs and images are plotted in a window, I would like to add in the window two buttons to export these data respectively in a excel file (so with no interactivity) and in a HTML file (to keep interactivity).
The first point is no trouble for me: I use xlsxwriter to export images and graphs as images. The problem is the second point: I would like to export all these data keeping interactions in graphs in a single HTML with a certain design I choose. Remember the fact that I want to build a standalone .exe file, because this program will run in a PC with Python not installed.
My question is this: is there some python library or html writer in python I can use to do this?
P.S.: plotly graphs are not subplots of a single plots but each one is a single plot, each one will have its own zoom etc. commands.

In python's Bokeh, how can I remove text above the plot?

With the following code:
import bokeh.plotting as bplt
bplt.output_file('output.html', mode="cdn")
I get an html file with my graph(s); but it has the text:
You have 1 plots
Close All Plots
Above the graph.
Is there a way to produce html output without this text?
As of Bokeh 0.5 there is a much more convenient embed module, which should provide the functionality you desire.
In your specific case, I would suggest the following setup:
Load BokehJS from CDN at the top of your page (or in the head)
<script src="http://cdn.bokeh.org/bokeh-0.5.1.js"></script>
In the Python script generating the plots, run
bokeh.embed.components(bokeh.plotting.curplot(), bokeh.resources.CDN)
for each plot. That will return a tuple with a <script> string containing the plot generation code, and a <div> string you can place anywhere on your page as a target.

A text only PDF page using matplotlib

I am generating a multi-page PDF with different graphs in each page using matplotlib. I would like to add another page that contains some information relevant to these graphs. But all text addition methods I've seen in matplotlib so far, seem to require a figure to be present already. Is it possible to add a text only page in matplotlib?

How to combine two charts into the single PDF using ReportLab?

Question : I'm generating charts using ReportLab. Charts are generated properly but into different PDF. I want to combine them into a single existing pdf.
basic structure of code is
class BreakdownPieDrawing():
def firstChart():
#code for generating first Pie chart
def secondChart():
#code for generating second Pie chart
if __name__=="__main__":
drawing1 = BreakdownPieDrawing()
drawing1.firstChart()
drawing1.save(formats=['pdf'],outDir='.',fnRoot='first')
drawing2 = BreakdownPieDrawing()
drawing2.secondChart()
drawing2.save(formats=['pdf'],outDir='.',fnRoot='second')
for full code Snippets please refer http://www.reportlab.com/snippets/4/
This code produces two separate PDFs. How can i combine them into single PDF.
I tried this to code :
def makePdf(self,drawing):
doc = SimpleDocTemplate('hello.pdf')
doc.build(drawing)
and then after I'm passing "BreakdownPieDrawing" class's object into this method. But this approach is not working.
I'm new to reportLab and python so pardon me for such a ugly code.
So the question is how to add this charts into existing pdf. Any help would be greatly appreciated.
If you look closely at the code snippet you provided (disclaimer: I wrote ;-) ) specifically at line#33 you see
# adding a pie chart to the drawing
self._add(self,Pie(),name='pie',validate=None,desc=None)
That lines adds the Pie chart to the drawing, you will then need to add your second chart to the same drawing you use the _add method, again like the snippet does on line#46 for adding the legend. Your drawing will have the two charts and when you save it as PDF you should get them both.
Are these two charts actually full page? If so, you can just call for a page break between drawing the two. Otherwise you can just adjust the coordinates so that both will fit on the page.
Alternatively, if you are doing something more complicated and will end up using Platypus, it might make sense to create a custom Flowable to render them.

Categories