Downloading Plotly interactive graphs in html and pdf format

Hi Everyone,

I just developed my first two apps which aren’t all that complicated. For the second app I access world bank data and have developed a way for the client to get a plot of whichever country , indicator and data source they select. Being am economics student , I always found it difficult to go online and look for data and then plot it. This is convenient and fast. However there do exists websites that also show plots of data which one can download from there as well. However to make my app distinguishable I wish to make a system wherein , if the client presses a button the plotly graph which is displayed( and is interactive) gets dowloaded as an html file in the clients system. This would be an advantage over all other sites that only allow non-ineteractive image downloads. I also want to provide a choice for a static image download.

My main question thus is regarding , how can I make a button which when clicked download the displayed fig in a html and pdf format ??? Can it be done on anvil? and if so could someone guide me …

Thank You.

The plot would need to be converted on the server side and then sent to the client. Here is an idea that should work, but I haven’t tested it. This is a bit more roundabout than you probably want, but from what I know it’s probably the easiest method.

  1. If your plot is being made on the client, you would first send your plot to the server function
  2. Write the plot to a data table row, being sure to save the row ID. You could write a background function that periodically removes these.
  3. Load the media object and send to the client.

Below I referenced plotly docs and a post on the forum.

1 Like

Hi @aditbiha12345,

Converting a form (including a Plotly graph) to PDF is really easy! We even have a few tutorials and examples, as well as our documentation!

Thank you eveyone, but i have managed to figure it out.