Python Dash vs. R Shiny – Which To Choose in 2021 and Beyond


Developing dashboards is no small task. You have to think about a vast amount of technical details and at the same time build something easy and enjoyable to use. Let’s say you have those areas covered. The question remains – which technology should you use? R or Python? Dash vs. Shiny?

Today we’ll compare two technologies for building web applications – Python Dash and R Shiny. After reading, you’ll know how these two compare and when it’s better to use one over the other. You’ll also see if it’s worth it to make a long-term switch to either. For a truly immersive face-off experience, download the source code of the sample dashboard used to illustrate Dash and Shiny capabilities.

Updated: March 1, 2022.


Introduction

At Appsilon, we are global leaders in R Shiny and we’ve developed some of the world’s most advanced R Shiny dashboards, so we have a natural bias toward using Shiny. Still, we’ll do our best to provide an honest and unbiased opinion in this article. We’re not going to throw arbitrary points to Shiny just because we prefer it for enterprise app development.

It’s also worth noting that whether you choose Dash or Shiny (or both!), you can deploy your apps through RStudio Connect. With Connect, you can now share Flask APIs and interactive dashboards written in both R and Python. Appsilon is a Full-Service Certified RStudio Partner and can assist with deployment and app scaling regardless of your choice of the underlying technology.

Library Overview for Dash and Shiny

Let’s start with Dash. It is a Python framework used for building web applications. It’s written in Flask, Plotly.js, and React.js, so it’s an ideal candidate for creating dashboards. If you’re a heavy Python user, Dash allows you to express your analysis quickly and visually.

Here’s an example dashboard you can create with Dash:

Image 1 - Ternary Map Explorer Dash dashboard

Image 1 – Ternary Map Explorer Dash dashboard

Want to see more dashboard examples? Check out Plotly’s official app gallery.

On the other hand, R Shiny is an open-source package for building web applications with R. It provides a robust web framework for developing any sort of app, not only dashboards. Shiny is easy and intuitive to use, as you’ll see in the examples below. It also doesn’t require any HTML, CSS, or JavaScript knowledge – but this is helpful if you want extra customizability.

Here’s an example dashboard you can create with Shiny:

Image 2 - Shiny Enterprise Dashboard

Image 2 – Shiny Enterprise Dashboard

Winner: Tie. You can develop identical solutions with both Dash and Shiny.

Dash vs. Shiny: Which Requires More Boilerplate Code?

Every web framework comes with a chunk of code needed for the application to run, named boilerplate. This section will show you how much code is needed to start Dash and Shiny application. You will create two identical applications by the end, each showing only a single H3 element. Let’s begin with Dash.

Here’s the corresponding application:

Image 3 - Basic Dash application

Image 3 – Basic Dash application

So eleven lines in total, and we haven’t imported any data visualization library. Three lines are empty, which are used for formatting purposes. In general – not bad. Let’s see what’s the deal with Shiny:

Only nine lines here, of which three are empty. Here’s the corresponding application:

Image 4 - Basic Shiny application

Image 4 – Basic Shiny application

Winner: R Shiny. Does it really matter much, though? It’s only boilerplate code, after all. At this initial stage – no, it seems like it doesn’t matter. However, for more advanced applications, Dash requires a lot more boilerplate code than Shiny. For instance, there are no reactive intermediate variables with Dash, which is a big drawback. We’ll return to this theme of Shiny ease-of-use throughout the article.

How to Create UI Elements in Dash vs. Shiny

Let’s continue our comparison by taking a look at UI elements. The goal is to create the same form-based application in both Dash and Shiny. The application should be used to filter job candidates by level, skills, and experience. It also allows you to specify additional points of interest.

Let’s start with Python’s Dash. All of the core UI components are available in the dash_core_componenets library. The convention is to import it abbreviated as dcc. Other imports and boilerplate remain the same. 

Here’s the code for a simple form-based application:

And here’s the corresponding application:

Image 5 - Simple form-based application in Python Dash

Image 5 – Simple form-based application in Python Dash

Dash doesn’t include too many styles by default, so you’ll have to do it independently It can be considered both as a pro (advanced CSS users will have to reset the styles anyway) and as a con (if you want to stick with default stylings). 

Let’s replicate the same application with R and Shiny:

Here’s the corresponding application:

Image 6 - Simple form-based application in R Shiny

Image 6 – Simple form-based application in R Shiny

As you can see, Shiny includes a ton more styling straight out of the box. Shiny applications look better than Dash applications by default. However, who wants their apps to look “default” anyway? We’ll cover custom styling in the next section.

Winner: R Shiny. You can create a better-looking application with less code.

How to Style UI with CSS in Dash vs. Shiny

Nobody likes a generic-looking application. The aesthetics of your app are tied directly with how users feel about it. With advancements in design, we’re used to commercial apps looking spectacular. That doesn’t mean developing great-looking apps is easy, especially for developers.

Still, adding a touch of style through CSS is more or less a must for your app. This section compares how easy it is to add styles to both Dash and Shiny if the same stylesheets look identical across the two. Who knows, maybe default stylings on Shiny will come as a drawback. Later, we’ll compare how easy it is to add custom CSS frameworks like Boostrap to your app.

A CSS file for the Dash application goes to the assets folder and in the www folder for Shiny apps. Create these folders in a root directory, where your application file is. 

Here’s the complete CSS for both Dash and Shiny – called main.css:

Let’s now use it to create a simple styled application – first with Dash:

Here’s the corresponding application:

Image 7 - Styled Dash application

Image 7 – Styled Dash application

The stylings work just as for any regular web application. That’s because Dash didn’t add its default styles as Shiny did.

Here’s the code for a styled R Shiny app:

And here’s the corresponding dashboard:

Image 8 - Styled Shiny application

Image 8 – Styled Shiny application

Well, that obviously doesn’t look right. The more elaborate default Shiny styling is conflicting with our custom styling. Shiny needs a bit more work with stylings than Dash, but that’s something you can quickly get used to. Still, the included styling with default Shiny apps means that there is a bit more work required to add custom styling to a Shiny app than a Dash app at a basic level.

Winner: Dash. This doesn’t mean you can’t make Shiny apps look fantastic, though.

How to Style UI with Bootstrap in Dash vs. Shiny

Let’s discuss CSS frameworks. Bootstrap’s been one of the most popular frameworks for years, so naturally, you might want to include it in your apps. It’s a great way to introduce new design elements and give your apps a fresher look. Your apps will still look kind of “default” – that’s mostly because Bootstrap has been out for so long and we’ve come to associate it with a “standard” appearance. Anyone who has been in web design/development for more than three days knows how Bootstrap components look like.

Including Bootstrap in Dash is easy. You have to install the dash_bootstrap_components library and you’re good to go. The code below shows you how to create a navigation bar and a jumbotron in Dash:

Here’s the corresponding application:

Image 9 - Dash and Bootstrap

Image 9 – Dash and Bootstrap

R Shiny is different. It comes with Bootstrap out of the box, but not with the most recent version. Bootstrap version 4.5 is the latest at this point, but Shiny is still stuck on 3.3.5. One solution for addressing this issue is by using the bslib library:

Image 10 - Shiny and Bootstrap

Image 10 – Shiny and Bootstrap

As you can see, it is a code-heavy solution. It requires you to specify every CSS class and other properties as if you were writing in pure HTML. Declaring a winner in this department is a no-brainer.

Winner: Dash. Using Bootstrap is much cleaner in Dash than in Shiny.

Reactivity in Dash vs. Shiny

Dashboards shouldn’t look and behave like plain reports. They have to be interactive. Users won’t like your dashboards if they can’t easily change what’s displayed and even interact with individual data points. That’s where reactivity (or callbacks) comes in. Options are endless – you can update every component as a single input change, update only selected components, delay updates until the button is pressed, etc. We’ll stick to the basics and perform the update when any of the inputs change.

For this example, we’ll have a single text input and two dropdown menus. Their values determine what the visualization looks like. The text input is used to change the title, and the two dropdowns are used for attributes shown on the X and Y axes.

Let’s start with Python and Dash. Here’s the code:

And here’s the corresponding dashboard:

Image 11 - Reactivity demonstration with Python Dash

Image 11 – Reactivity demonstration with Python Dash

It’s a simple dashboard but requires a fair amount of code. Nevertheless, the code is simple to read and understand. Dash uses @app.callback decorator pattern to handle reactivity. You can update as many components in a single callback and get values from as many components as needed.

R Shiny is a bit simpler. It needs significantly less code to produce the same output. Still, the syntax might look strange if you’re not used to R (e.g., double exclamation point in front of column names). 

Here’s the code for producing the identical dashboard:

Here’s the corresponding dashboard:

Image 12 - Reactivity demonstration with R Shiny

Image 12 – Reactivity demonstration with R Shiny

Winner: R Shiny. Shiny requires less code than Dash for better-looking output.

Publishing and Deployment in Dash vs. Shiny

Dashboard development is fun, but what about deployment? Most businesses don’t tend to leave dashboards sitting idle on a developer’s PC. Whether you’re working for yourself or for a client, publishing/deployment is a necessary step. As it turns out, you’re not limited to either library.

When it comes to R Shiny, deployment possibilities are next to endless. You can host your app as a GitHub gist (single file only), use a service such as shinyapps.io, do everything manually by hosting a Shiny Server, create a Docker container around the dashboard, and everything in between.

Want to learn more about sharing Shiny apps? Here are three free options – from simple to AWS.

The same holds true for Python and Dash. Sure, you can’t use online services specific to R Shiny, but we don’t see that as an issue. It’s likely you want full control over the deployment process, especially if you’re working on a dashboard for a client. You can’t go wrong by Dockerizing your Dash application and deploying it to the cloud (e.g., on Amazon AWS EC2 instance). With Dash, you also have the option to use Dash Enterprise for deployment, which isn’t free.

There are enterprise options for R Shiny too, but you get the gist – deployment isn’t a deciding factor.

Winner: Tie. You can deploy both Shiny and Dash apps pretty much everywhere.

Python Dash vs. R Shiny: Final Face-off

The final results are in:

  • R Shiny – 3 points
  • Python Dash – 2 points
  • Tie – 2 points

It looks like R Shiny is ahead by a single point. Does this mean that R Shiny is better for everyone and every scenario? Absolutely not. You can develop identical production-ready applications in both technologies. What you choose depends on your specific needs and preferences.

R Shiny is a bit faster for developers. It requires less code than Dash for identical solutions. That’s if you decide to not use Bootstrap in your dashboards. Further, creating custom components in Dash requires extensive React.js knowledge, which is a large hurdle. Dash also falls short with intermediate reactive variables. Using them requires you to create a hidden div to store and reuse calculations. An alternative solution exists, but it’s still a big drawback when compared to R Shiny.

What else can you do with Shiny? Check out our free Shiny dashboard templates.

If you need to create powerful, customizable, and interactive dashboards that look great and respond to user input, Shiny is a clear choice. It requires a bit of coding knowledge even for simple dashboards, but R isn’t a very complicated language. You can quickly get up to speed in a couple of weeks or even a couple of days, depending on your prior knowledge of programming. If you want to make a scalable enterprise Shiny dashboard, then you can always reach out to Appsilon for help. We’re continuously pushing the limits of what’s possible with Shiny, and we’d be happy to guide you and your company.

Learn More