Shinylive Essentials for Python Cheatsheet

Quick Reference Guide to Serverless Shiny Apps with Python

Essential tips, commands, and best practices for creating, deploying, and troubleshooting Shinylive Python applications.

Tools
Author
Affiliation
Published

March 22, 2025

Keywords

Shinylive Python, serverless Shiny Python, Pyodide Shiny, Shiny Python

Shinylive Python Installation & Deployment

Installation from PyPI

Install the latest stable version of Shinylive Python:

pip install shinylive

Installation from GitHub

To install the development version:

pip install git+https://github.com/posit-dev/py-shinylive.git

Exporting and Deploying Your App

Export your Shiny app as a static webpage:

shinylive export my_app_dir my_site_dir

Preview locally:

python3 -m http.server --directory my_site_dir 8000

Access at: http://localhost:8000

Detailed Tutorial on Installation & Deployment



Creating Basic Shinylive Python Apps

Minimal Shinylive App Example

from shiny import App, ui, render

app_ui = ui.page_fluid(
    ui.input_slider("n", "N", 0, 100, 40),
    ui.output_text_verbatim("result")
)

def server(input, output, session):
    @output
    @render.text
    def result():
        return f"You selected {input.n()}"

app = App(app_ui, server)

Export and Preview

shinylive export my_app my_site
python3 -m http.server --directory my_site

In-depth Guide to Creating a Basic App

Quarto Integration Tips for Python Apps

Installing the Shinylive Quarto Extension

From terminal within your Quarto project:

quarto add quarto-ext/shinylive

YAML Setup for Shinylive

In your .qmd document:

---
format: html
filters:
  - shinylive
---

Embedding Apps in Quarto

```{shinylive-python}
#| standalone: true
from shiny import App, render, ui

app_ui = ui.page_fluid(
    ui.input_slider("n", "Number", 0, 10, 5),
    ui.output_text("out")
)

def server(input, output, session):
    @output
    @render.text
    def out():
        return f"Square of {input.n()} is {input.n()**2}"

app = App(app_ui, server)
```

Detailed Quarto Integration Guide

#| '!! shinylive warning !!': |
#|   shinylive does not work in self-contained HTML documents.
#|   Please set `embed-resources: false` in your metadata.
#| standalone: true
#| viewerHeight: 300
from shiny import App, render, ui

app_ui = ui.page_fluid(
    ui.input_slider("n", "Number", 0, 10, 5),
    ui.output_text("out")
)

def server(input, output, session):
    @output
    @render.text
    def out():
        return f"Square of {input.n()} is {input.n()**2}"

app = App(app_ui, server)

Troubleshooting Common Issues

App Does Not Load

  • Ensure the Shinylive extension and dependencies are installed correctly.
  • Verify the export path and static assets.

Missing Python Package

If a package is missing:

import micropip
await micropip.install("pandas")

Browser Compatibility

  • Use a modern browser like Chrome, Firefox, or Edge.
  • Check browser console logs (F12) for detailed error messages.

Advanced Troubleshooting Guide

Further Reading


Back to top

Reuse

Citation

BibTeX citation:
@online{kassambara2025,
  author = {Kassambara, Alboukadel},
  title = {Shinylive {Essentials} for {Python} {Cheatsheet}},
  date = {2025-03-22},
  url = {https://www.datanovia.com/learn/interactive/cheatsheets/shinylive-essentials-python.html},
  langid = {en}
}
For attribution, please cite this work as:
Kassambara, Alboukadel. 2025. “Shinylive Essentials for Python Cheatsheet.” March 22, 2025. https://www.datanovia.com/learn/interactive/cheatsheets/shinylive-essentials-python.html.