Shiny for Python Workshop
Introduction
This is the workshop originally prepared for posit::conf 2023. It has been reviewed and updated by Appsilon.
Background
This workshop is aimed at people who are somewhat familiar with doing data analysis in Python, but do not have much of a background in Shiny. If you are brand new to Python we recommend spending a bit of time familiarizing yourself with the following topics before the workshop:
- How to install Python packages in a virtual environment
- How to do basic data manipulation with pandas or polars
- How to draw plots
- How to clone a repository with git
Setup
There are two ways to work through the examples and exercises in this workshop.
1) In your web browser with Shinylive
Shinylive allows you to run full-featured shiny apps in your browser, and includes a basic editor which is good enough to run examples. As a result you should be able to work through all of the examples in the workshop using just the browser without installing anything locally.
2) Locally with VS Code
While Shinylive is great, it likely isn’t the environment you’ll use to develop Shiny apps, and so it makes sense to set up VS Code and run the examples locally. To do this follow these steps before the workshop:
- Install VS Code
- Install the Shiny for Python VS Code extension
- Clone the repository with
git clone https://github.com/Appsilon/shinyconf-pyshiny-workshop.git
, or alternately download the repository as a zip file:
- Navigate to the project directory and create a new virtual environment with
python3 -m venv .venv
- Set your python interpreter to the virtual environment with
CMD + SHIFT + P
>Select Interpreter
- Open a new terminal prompt, which should switch to
(.venv)
- Install the relevant packages with
pip install -r requirements.txt
All of the example apps are stored in the /apps
directory. The examples are in apps/examples
and the problem sets are in apps/problem-sets
. If you’ve installed the Shiny for Python VS Code extension, you can run any of the apps by opening the app.py
file and clicking the play button in the top right. (See screenshot)
Alternatively, run them from the command line with shiny run <path-to-app.py> --reload
.