The world’s leading publication for data science, AI, and ML professionals.

Understanding the Two Faces of Shiny for Python: Core and Express

Exploring the Differences and Use Cases of Shiny Core and Shiny Express for Python

Photo by Vincent van Zalinge on Unsplash
Photo by Vincent van Zalinge on Unsplash

Posit is building their presence in the space of Python at a really fast pace. Shiny for Python was announced last year, and the Shiny Express announcement followed not long after. But if you are new to the world of Shiny or Python, which tool should you learn first, and how do you seamlessly switch from one to the other? In this article, I will cover the structural breakdown of Shiny "Core" and "Express" and their key differences.


What are all the Shiny things?

Shiny "Core"

Shiny for Python is a framework for building interactive web applications in Python. I will cover some foundational components of Core Shiny in this article, but if you would like to go further in-depth and learn how to build a web application from foundation to styling using Shiny Core, check out my previous article on this topic.

Shiny "Express"

Shiny Express is designed to make it significantly easier to get started with Shiny, and to write simple apps with a minimum of boilerplate.

Why was Express needed if Core already existed?

According to Posit, Shiny Core has a great advantage over other web application frameworks for Python because of its efficiency. For instance, Streamlit re-renders the entire application script when a user inputs something, while Shiny only re-executes the parts of the application that need to be updated. Shiny also provides a robust, ever-evolving list of features to build complex web applications.

However, the advantage of Streamlit is that it is easy to get up and running on, build quick prototypes and iterate faster. Shiny Express was Posit’s answer to this specific advantage that was missing from Shiny Core to bring the best of both worlds together – efficiency and quick prototyping.

So let’s get into how they are both structured.


Setting up the Python environment

  • Install the Shiny for Python extension (For VSCode)
  • Install the required package by running pip install shiny.

Getting started with a Shiny application

This foundation command makes it very easy to get started with a Shiny template.

Shiny create --help

This command opens up options for various Shiny templates. These initial options do not differentiate between Core and Express.

I will pick the basic-app template and run the command shiny create -t basic-app. When I run this command, I am given the option to create a Shiny Express web application, and if I select no, a Core application template is created by default.

shiny create -t basic-app

Either option creates a folder called basic-app in the selected directory with an app.py file. Let’s compare the contents of the app.py file.


Comparing app.py file structure

Below is what Core and Express look like, both app.py file and its output. The output is pretty similar, but the main differences are in how app.py structures ui and server functions.

Shiny Core:

In Shiny Core, similar to R Shiny, there is a ui and server component within the app.py file. The ui contains the frontend of the application and the server logic handles the backend.

In the app above the ui has these three components:

  • ui.panel.title to create the "Hello Shiny" title.
  • ui.input.slider to create a slider for the values of N.
  • ui.output_text_verbatim that will pull the text output from the server logic and display it verbatim.

The server has the following component

  • render.text to define the logic of calculating N*2 and pass it as a text string to the ui function where it will be displayed on the frontend.

Shiny Express:

Shiny Express on the other hand, does not separate the ui and server functions. The frontend and backend logic flow as a single series of code blocks as below.

The components of this application are

  • ui.panel.title to create the "Hello Shiny" title.
  • ui.input.slider to create a slider for the values of N.
  • render.text to define the logic of calculating N*2 and displaying it directly as a text string instead of passing it to any ui function.

In Express whatever runs is displayed in the order the command is run. In Core, the ui function has the order in which everything will be displayed in the frontend, independent of the sequence of steps on the server side. This difference will become much clearer with the next example of how to add new components to each application.


Adding new components to the web application

I will now add a second title, slider, and text output to my web application. Let’s see first what that looks like in Shiny Core.

Shiny Core:

In addition to the existing components, within the ui function I will add these three components:

  • ui.panel.title to create the "One more slider" title.
  • ui.input.slider to create a slider for the values of Z.
  • ui.output_text_verbatim that will pull the text output from the server logic and display it verbatim.

Within the server function, I will add the component below:

  • render.text to define the logic of calculating Z*3 and pass it as a text string to the ui function.

This is what the full code and output looks like now for Shiny Core:

Shiny Express:

On the other hand, within Shiny Express since there is no ui and server function split, I will add the frontend and output components in my code as I want them to appear in my web application.


Why are these differences important?

While it may seem like a small difference in the approach to structuring the application, I believe this has major impact on the types of scenarios these two approaches light up. For instance:

Development scenario

  • Shiny Express allows for quick prototyping in line with the advantage that Streamlit has. While building the code, you do not have to focus much on the structure but really the flow of how you want the information to appear in the application.
  • Shiny Core on the other hand provides a very structured approach that may be time-consuming to create at first but works well as the application grows in size.

Learning ability

  • Shiny Express is quicker to learn, so it can be a good first step to entering the world of Shiny.
  • Shiny Core takes a bit of time to learn and get used to the structure, but is worth the effort as the application scales and moves beyond prototyping.

Translating code from one format to another

On the Shiny for Python documentation pages, all/most code snippets have been updated to include examples of both, Core and Express. For instance, in the example below to create a drop-down menu, there are two tabs of code, one for each face of Shiny.


Is Shiny Core going away now that Express has arrived?

No. Not according to Posit’s announcement of Shiny Express. Here are a few snippets from it that suggest they are both here to stay and will continue to serve the purpose of building web applications that cater to all user scenarios from prototype to production.

The announcement also clarifies how the two fit together.


Which one to start with?

  • First and foremost, consider the scenario you are going after because Shiny Express is great for prototyping whereas Shiny Core is great if you are looking for structure to create a complex app.
  • If you come from Streamlit background, Shiny Express is a great entry point.
  • If you come from Shiny R background, then Core Shiny’s structure will seem extremely familiar to get started with.
  • Shiny Core has a steeper learning curve, so Shiny Express can act as a good gateway framework.

I hope this article has provided you with a clear understanding of the differences between Shiny Core and Shiny Express and how to get started with either of them. Keep an eye out on this growing ecosystem of Python tools from Posit.

If you want to delve deeper into building an application with Core Shiny from foundation to styling, check out my previous article on the topic where I create a "Who is the Goodest Doggy" web application.


If you’d like, find me on Linkedin.


All images in this article are by the author, unless mentioned otherwise.


Related Articles