save ipython html object as pdf - python

I'm plotting some data using shap, which returns me (in console) a
<IPython.core.display.HTML object>. I would like to convert the object to a PDF and save it.
I do understand that there is some hassle, as I probably would need to simulate a browser to open and view the HTML in.
What would be the most straight-forward way of storing the html output as PDF?
Please note that I am not inside a browser/iPython notebook, and I do not want to create and convert a whole iPython notebook.

Related

How can I save ALL my ipython outputs in a file? (maybe like html?)

I want to save all the outputs generated (both textual, plots, etc.) to be saved so that I can access it at a later point of time (Similar to how SAS generates .html files for this).
For example:
Skewness: 1.882876
Kurtosis: 6.536282
Here I want to have both the Plot as well as the skewness and kurtosis saved in a file so that I can check it later. How can I do this?
Note: I already tried the %logstart -o but it only captures the outputs with a Out[x]. Unfortunately, neither print statement, nor matplotlib plots generate these Out[x] in iPython.
I am using Spyder if that's helpful in any way.
Thanks in advance!
Edit: I found that you can do right-click ipython console and just save it as HTML. But if you have lots of outputs, then this html doesn't include all of the outputs
Use Jupyter Notebook and save html from browser

Download Plotly HTML From Databricks

I have a plotly figure that I want to download the HTML for.
When I try:
fig.to_html()
It will only output some of the HTML string and ends with this:
*** WARNING: skipped 3421789 bytes of output ***
Does anyone know how I can force databricks to show all of the HTML or copy it to my clipboard?
Still a bit hacky, but the following should work to save and download a file from Databricks containing the html:
Assuming you have a plotly figure object and are working in a databricks notebook:
Create an html string and assign a variable to it:
html_string = fig.to_html()
Save to the databricks filesystem using dbutils:
dbutils.fs.put("/FileStore/my_html_file.html", html_string)
Download the html string by navigating in a browser to:
https://<databricks-instance>/files/my_html_file.html
Note:
The databricks instance is usually something like <some_letters>-<some_numbers>.databricks.net
If you're within an organisation (i.e. your databricks URLs typically end in "?o=<organisation_id>"), then you may need to add this to the end of the URL in step 3.

save python visualization panel as html

I am working on Panel along with Holoviews. I would like to save it to the HTML file so that I can call it from my website.
Following this, I found that the panel is able to save the file in HTML format. However, it is static and does not reflect changes based on the other components.
panel.save()
I am not able to save it even to JSON as described in the same link through this command
panel.embed().save_path(default='./holoviews-examples')
Any solution.
I think you're misinterpreting the docs a little bit, save_path is not a method, it's an argument to the embed and save methods, e.g.:
panel.save('test.html', embed=True)
If you then want to export to JSON files you can also enable that with:
panel.save('test.html', embed=True, embed_json=True)
and optionally provide a save_path and load_path.

How to prevent charts or tables to disappear when I re-open Jupyter Notebook?

I use Pandas with Jupyter notebook a lot. After I ingest a table in from using pandas.read_sql, I would preview it by doing the following:
data = pandas.read_sql("""blah""")
data
One problem that I have been running into is that all my preview tables will disappear if I reopen my .ipynb
Is there a way to prevent that from happening?
Thanks!
Are you explicitly saving your notebook before you re-open it? A Jupyter notebook is really just a large json object, eventually rendered as a fancy html object. If you save the notebook, illustrations and diagrams should be saved as well. If that doesn't do the trick, try putting the one-liner "data" in a different cell than read_sql().

Saving Ipython Notebook with html figures as pdf?

I am using Ipython Notebook and I would like to save the notebook as pdf. When a notebook contains html figures in markdown mode I cannot export them
In example:
<img src='http://draftingmanuals.tpub.com/14262/img/14262_140_2.jpg'>
represents the following:
However, when I download the notebook as PDF via LaTeX (pdf) the result is without the figure:
Is this a bug or can I avoid this somehow?
This is not really a bug, but a known limitation. Actually there are two issues in your example:
the raw html <img> tag gets stripped when the markdown cells are converted by pandoc to latex (see pandoc docu).
you link to a remote image, which is (currently) not downloaded prior to the conversion.
Thus, it is a bit tricky to get what you desire. The first issue may be overcome by means of a custom filter and custom template. For the second, you may need a custom preprocessor.
Alternatively, you could use python with urllib (e.g. Downloading a picture via urllib and python) and matplotlib to display this image. Such embedded images are converted fine.

Categories

Resources