Download Button to download a pn.Row() from my app

is it possible to add a download button that will download a pn.Row() containing plots and other goodies?
something that will allow the user to save it as an html file on his computer
can i somehow use FileDownload for this purpose?

so far i was able to make a function that is triggered by a button that runs pn.Row().save(‘test.html’)
but it wont let the user decide where to save it

Sure that’s possible, you just have to provide a callback which writes the HTML to a StringIO object and returns that, e.g.:

import io
import panel as pn

pn.extension('vega')

vegalite = {
  "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
  "data": {"url": "https://raw.githubusercontent.com/vega/vega/master/docs/data/barley.json"},
  "mark": "bar",
  "encoding": {
    "x": {"aggregate": "sum", "field": "yield", "type": "quantitative"},
    "y": {"field": "variety", "type": "nominal"},
    "color": {"field": "site", "type": "nominal"}
  }
}
vgl_pane = pn.panel(vegalite, height=240)

layout = pn.Row(vgl_pane)

def download_layout():
    sio = io.StringIO()
    layout.save(sio)
    sio.seek(0)
    return sio

download = pn.widgets.FileDownload(filename='layout.html', callback=download_layout)

pn.Row(
    download,
    layout
)
3 Likes

Hi @alonsht

You can find more details about embedding and saving here Deploy and Export — Panel 0.12.0 documentation