Introducing: Shiny Express

A brand new way to write Shiny apps in Python
Author

Shiny Team

Published

January 29, 2024

Shiny Express logo

Today we’re officially announcing the most important addition to Shiny for Python since its inception: Shiny Express, a new way to write Shiny apps in Python!

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

Here’s what a simple “Hello, World” app looks like in Shiny Express:

from shiny.express import input, render, ui

ui.input_text("name", "What's your name?", value="World")

@render.text
def greeting():
    return f"Hello, {input.name()}!"

The ui.input_text() function creates a text input, and the @render.text decorator makes the output of the greeting() function appear on the page.

After installing Shiny with pip install shiny, you can save this code as app.py and start the app with shiny run app.py. Or, skip the install and try the app in our online editor.

Here’s another example with more features of Shiny Express, including UI container components (sidebar and card) and a plot:

from shiny import reactive
from shiny.express import input, render, ui
from shinywidgets import render_plotly

ui.page_opts(title="Penguins dashboard", fillable=True)

with ui.sidebar():
    ui.input_selectize(
        "var", "Select variable",
        ["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g", "year"]
    )
    ui.input_numeric("bins", "Number of bins", 30)

@reactive.calc
def df():
    from palmerpenguins import load_penguins
    return load_penguins()[input.var()]

with ui.card(full_screen=True):
    @render_plotly
    def hist():
        import plotly.express as px
        p = px.histogram(df(), nbins=input.bins())
        p.layout.update(showlegend=False)
        return p

Simple, yet powerful

While Shiny Express is easy to pick up, it’s powered by Shiny’s proven reactive programming framework, extensive (and growing) suite of components, and deeply customizable approach to UI—just in a more approachable syntax that minimizes the fuss. It’s suitable for writing everything from throwaway prototypes, to realtime dashboards, to cutting edge model demos, to production-quality business workflow apps.

One framework, two ways to author

Our traditional syntax for writing Shiny apps is now called Shiny Core. If you’re already happily using Shiny, no need to change what you’re doing! We think of Shiny Express and Shiny Core as complementary, and intend to support both syntaxes indefinitely.

Shiny Core is a more structured approach to writing Shiny apps, and we think it’s still the best choice for larger, more complex apps. Here’s what that same “Hello, World” app looks like in Shiny Core:

from shiny import App, ui, render

app_ui = ui.page_fluid(
    ui.input_text("name", "What's your name?", value="World"),
    ui.output_text("greeting"),
)

def server(input, output, session):
    @render.text
    def greeting():
        return f"Hello, {input.name()}!"

app = App(app_ui, server)

Although there’s more to learn and more to type, the enforced discipline of separating UI and server logic can be a benefit for larger apps.

That being said, we think most new Shiny users will be more successful starting their learning journey with Shiny Express, so we’ve overhauled our main tutorial to encourage people to start there. The more advanced topics are written for both Express and Core, as are our Component and Layout galleries.

Learn more

You can get started with Shiny today by jumping into the tutorial. Thanks to Shiny Express, it’s never been easier!

Or if you’re already experienced with Shiny, you find out more about the differences between Express and Core.

Questions? Comments? We’d love to hear from you! Please join us on Discord.

Questions

How do I install Shiny Express? Is it an add-on package?
Shiny Express is built into shiny 0.7.0. You can install it with pip install shiny (or upgrade with pip install -U shiny).

Is Shiny Core syntax really going to stay around in the future?
Shiny Express is not intended to replace Shiny Core. In fact, Shiny Express could not exist without Shiny Core, because it is implemented using Shiny Core! As we were building Shiny Express, we were very pleased to find that Shiny Core provides a solid foundation on which to build this new set of abstractions.

Is Shiny Express available for R?
We don’t have immediate plans to bring Shiny Express to R. Given the size and maturity of the Shiny for R ecosystem, it would be a much larger undertaking to introduce a new syntax.

That being said, we’re excited to see how the Python community responds to Shiny Express, and we’ll be watching closely to see if there’s interest in a similar syntax for R.

In the meantime, if you’re a Shiny for R user and the syntax changes in Shiny Express resonate with you, the Shiny Document syntax is actually extremely similar to Shiny Express.