1

I have a couple of graphs that need to be shown on a local website, they're made with MPLD3, and I used the save_html option. However, I've just been told that the graphs need to be able to be viewed offline, so I wanted to know if there was a way to do this without mpld3.show(), because I need the graphs embedded in the website.

1 Answers1

1

Please elaborate if possible what you mean by "local website". It sounds like you have an index.html file on your hard drive that you're rendering in a browser.

If that's the case and you want this to work with no internet connection, then it's likely you'll have to embed the D3 javascript dependency and the mpld3 javascript dependency into the html file after you save it to the a file. I think the default behavior is to retrieve those libraries from a cdn rather than embedding them in full.

Another option would be to try using the fig_to_html() function kwargs d3_url= and mpld3_url= to set the paths to your locally stored D3 and mpld3 libraries using a "file://" prefix rather than the "https://" prefix (again, this just avoids loading the dependencies via cdn).

aorr
  • 937
  • 7
  • 9
  • Yes, what I mean is that I'm using an index.html file that I'm rendering in a browser. I was only made aware today that the plots were going to be viewed without an internet connection. So, fig_to_html has the option of linking the files saved on the computer? – Miguel Ángel Gárate Fox Oct 01 '18 at 21:14
  • I have not tested this so I cannot say for sure, but I do recommend giving those kwargs a try to specify the path to your local files. If that doesn't work then you can modify the html yourself after exporting it to force it to load local copies of the dependencies libraries, or to embed the full library in to the html file's – aorr Oct 01 '18 at 21:50
  • Modifying the files myself is not an option, unfortunately. The graphs are being updated constantly. What output does fig_to_html give? Since there's no way of specifying a path to save an html file. – Miguel Ángel Gárate Fox Oct 01 '18 at 22:01
  • According to the docs at the link, `fig_to_html` produces a string. You may save that string to a file, embed it into a template, or add anything you want to it before writing/saving/rendering it (including appending whatever js dependencies you need). – aorr Oct 01 '18 at 22:37