Python Dash vs. R Shiny — Which To Choose in 2021 and Beyond
By: Dario Radečić
Tags: Data Visualization, Python, Towards Data Science, R, Data Science

Creating UI elements

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:

import dash

import dash_core_components as dcc

import dash_html_components as html



app = dash.Dash(__name__)

app.layout = html.Div(children=[

html.H1('Heading 1'),

html.Label('Filter by level:'),

dcc.Dropdown(

options=[

{'label': 'Junior', 'value': 'junior'},

{'label': 'Mid level', 'value': 'mid'},

{'label': 'Senior', 'value': 'senior'}

],

value='junior'

),

html.Label('Filter by skills:'),

dcc.Dropdown(

options=[

{'label': 'Python', 'value': 'python'},

{'label': 'R', 'value': 'r'},

{'label': 'Machine learning', 'value': 'ml'}

],

value=['python', 'ml'],

multi=True

),

html.Label('Experience level:'),

dcc.RadioItems(

options=[

{'label': '0-1 years of experience', 'value': '01'},

{'label': '2-5 years of experience', 'value': '25'},

{'label': '5+ years of experience', 'value': '5plus'}

],

value='25'

),

html.Label('Additional:'),

dcc.Checklist(

options=[

{'label': 'Married', 'value': 'married'},

{'label': 'Has kids', 'value': 'haskids'}

],

value=['married']

),

html.Label('Overall impression:'),

dcc.Slider(

min=1,

max=10,

value=5

),

html.Label('Anything to add?'),

dcc.Input(type='text')

])





if __name__ == '__main__':

app.run_server(debug=True)

And here’s the corresponding application:

Image 5 — Simple form-based application in Python’s Dash

Yeah, not the prettiest. Dash doesn’t include too many styles by default, so you’ll have to do it independently.

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

library(shiny)



ui <- fluidPage(

tags$h1("Heading 1"),

selectInput(

inputId = "selectLevel",

label = "Filter by level:",

choices = c("Junior", "Mid level", "Senior"),

selected = c("Junior")

),

selectInput(

inputId = "selectSkills",

label = "Filter by skills:",

choices = c("Python", "R", "Machine learning"),

selected = c("Python", "Machine learning"),

multiple = TRUE

),

radioButtons(

inputId = "radioExperience",

label = "Experience level:",

choices = c("0-1 years of experience", "2-5 years of experience", "5+ years of experience"),

selected = c("2-5 years of experience")

),

checkboxGroupInput(

inputId = "cbxAdditional",

label = "Additional:",

choices = c("Married", "Has kids"),

selected = c("Married")

),

sliderInput(

inputId = "slider",

label = "Overall impression:",

value = 5,

min = 1,

max = 10

),

textInput(

inputId = "textAdditional",

label = "Anything to add?"

)

)



server <- function(input, output) { }



shinyApp(ui, server)

Here’s the corresponding application:

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.