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

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