As this workshop is about Shiny for Python, you need to have a python environment set up so you can start creating your own apps.
- Online with Shinylive: This is recommended if you like to get started quickly and do not have a local Python Shiny development environment setup
- Local: This setup is recommended if you have experience setting up new workspaces quicky and installing the various requirements, it will also provide the most comprehensive experience and you get to keep all of your work
Shinylive allows you to build and run (simple) Shiny apps all from within the browser without the need to install anything (e.g. no need to setup Python, Shiny or even an IDE).
To learn more about the framework and its advantages and disadvantages, visit the shinylive documentation website
You can access Shinylive for Python via https://shinylive.io/py/editor/
Note that for this workshop, we will provide you with dedicated links for each exercise that already has start code and relevant files uploaded. These links can be found in each exercise's README. You can at any point also copy-paste code from this repo into the editor if needed or even upload files
NOTE: If you are using the dedicated links provided in each exercise's README in this repository, you should not have to upload any data unless specifically noted in the instructions.
- You can upload data from your computer into a shinylive app by clicking the
add
+icon next to theapp.pyfile. - To upload data to a subfolder, e.g.
wwwadd the relative path as part of the filename e.g.www/image.png - Alternatively, you can upload the data elsewhere, make it publicly available and use links instead to read the data in dynamically. We will provide this option where needed
If your app requires additional libraries outside of the core python modules or
the shiny library, you can add a requirements.txt file (create from
scratch) and add the libraries there so they will be installed when you run the
app.
Note that not all Python libraries are available in Shinylive. For a full list refer to the Pyodide website
- Git Clone: Navigate to the folder where you want to store this project and
then run
git clone https://github.com/pieterjanvc/RShiny2Python.git - Manual Download: Download and Unzip the repo anywhere on your computer
To check your current, default Python version, run the following command on the Terminal
python --version
Python 3.13 was used whilst creating the exercises, but older versions should work as well
It is highly recommended to choose an IDE that has extended Python support and integrates well with Shiny. Below is a list of the IDE's in order of recommendation.
Best if you code in both R and Python. This IDE is a fork of VS code, so if you are familiar with the latter it will be very easy to adopt working in it.
- Install Positron
- Install the Shiny extension
- Open the extension tab in Positron (ctrl/cmd + shift + x)
- Search for
Posit.shinyand install the extension - Reload if needed
Very similar to Positron, but recommended in case you use other programming languages as well and prefer not to install another IDE
- Install VS Code
- Install the Shiny extension
- Open the extension tab in Positron (ctrl/cmd + shift + x)
- Search for
Posit.shinyand install the extension - Reload if needed
There is only limited support for using Python Shiny in RStudio, but if you really prefer to work in it and don't want to use shinylive, you can make this work.
- Open RStudio
- Install the reticulate package
install.packages("reticulate") - Set the Python interpreter: Tools --> Global Options --> Python
It is recommended to setup a virtual python environment to ensure you have all the correct package versions, but this is optional.
- If you are using the built-in python environment manager use
requirements.txtto install all dependencies - If you are using uv, you can use the
uv.lockfile
Alternatively, install any required packages depending on the exercise you are at using the basic pip command in the Terminal. For example:
pip install shinyThis workshop has been tested with Shiny 1.3+. If you have an older version
already installed, add the --upgrade flag to this command to get the latest
version
You can now try and run the test_app.py file.
- If you are using Positron or VS Code can click the Run button located on the top-right of the file if you have the extension installed
- If you are using RStudio or would like to Start the app from the Terminal you run the following command
shiny run --reload --launch-browser test_app.pyTo stop the Shiny app, press ctrl/cmd + C in the terminal