Shiny
Framework for building web applications with R. Creates interactive dashboards and data analysis apps easily through reactive programming model. Enables web app development without requiring HTML, CSS, or JavaScript knowledge.
GitHub Overview
rstudio/shiny
Easy interactive web applications with R
Topics
Star History
Framework
Shiny
Overview
Shiny is a framework for building interactive web applications in R. Through its reactive programming model, you can create dynamic dashboards and tools that respond to data without knowledge of HTML/CSS/JavaScript.
Details
Shiny is a web application framework for R developed by RStudio (now Posit). Since its release in 2012, it has been widely adopted as a tool for R users to share data analysis results and enable interactive exploration. Its key feature is the reactive programming model, where outputs (plots, tables, text) automatically update in response to user inputs (sliders, buttons, text inputs). The separation of UI and server logic enables structured development of complex applications. Functions like reactive(), observe(), and isolate() enable efficient dependency management and computation optimization. Extension packages like shinydashboard, flexdashboard, bslib, and shinythemes make it easy to create professional-looking applications. Deployment options are comprehensive, including Shiny Server, shinyapps.io, and RStudio Connect, providing a consistent workflow from development to production.
Pros and Cons
Pros
- R Integration: Full-stack application development with only R code
- Reactive Model: Automatic dependency management and updates
- Rich UI Components: Diverse input and output widgets
- Extensibility: Custom widgets and modularization
- Easy Deployment: Various hosting options
- Active Community: Abundant tutorials and extension packages
Cons
- Performance: Limitations with large-scale applications
- Single-threaded: No parallel processing by default
- Scalability: Requires optimization for many concurrent users
- Customization Limits: Constraints for advanced UI requirements
Main Use Cases
- Business intelligence dashboards
- Data exploration tools
- Statistical analysis applications
- Machine learning model demos
- Research result sharing platforms
- Interactive educational materials
- Real-time monitoring
Basic Usage
Installation
# Install from CRAN
install.packages("shiny")
# Install development version
devtools::install_github("rstudio/shiny")
# Load library
library(shiny)
Basic Application
# app.R
library(shiny)
# Define UI
ui <- fluidPage(
titlePanel("Simple Shiny App"),
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
mainPanel(
plotOutput("distPlot")
)
)
)
# Define server logic
server <- function(input, output) {
output$distPlot <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white',
main = "Waiting Time Distribution",
xlab = "Waiting time (minutes)")
})
}
# Run application
shinyApp(ui = ui, server = server)
Reactive Programming
# Reactive expression example
server <- function(input, output) {
# Reactive expression (caches results)
filtered_data <- reactive({
mtcars %>%
filter(cyl == input$cylinders) %>%
filter(mpg >= input$mpg_range[1] & mpg <= input$mpg_range[2])
})
# Use reactive expression
output$plot <- renderPlot({
ggplot(filtered_data(), aes(x = wt, y = mpg)) +
geom_point() +
theme_minimal()
})
output$table <- renderTable({
filtered_data() %>%
summarise(
avg_mpg = mean(mpg),
avg_wt = mean(wt),
count = n()
)
})
# Observer (for side effects)
observe({
print(paste("Selected cylinders:", input$cylinders))
})
}
Advanced Features
# Modularization
# Counter module
counterUI <- function(id) {
ns <- NS(id)
tagList(
actionButton(ns("increment"), "Count"),
textOutput(ns("count"))
)
}
counterServer <- function(id) {
moduleServer(id, function(input, output, session) {
count <- reactiveVal(0)
observeEvent(input$increment, {
count(count() + 1)
})
output$count <- renderText({
paste("Count:", count())
})
return(count)
})
}
# Main app
ui <- fluidPage(
counterUI("counter1"),
counterUI("counter2"),
textOutput("total")
)
server <- function(input, output, session) {
count1 <- counterServer("counter1")
count2 <- counterServer("counter2")
output$total <- renderText({
paste("Total:", count1() + count2())
})
}
# Dashboard example
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Data Dashboard"),
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Analysis", tabName = "analysis", icon = icon("chart-line"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "dashboard",
fluidRow(
valueBoxOutput("value1"),
valueBoxOutput("value2")
),
fluidRow(
box(plotOutput("plot1", height = 250)),
box(plotOutput("plot2", height = 250))
)
),
tabItem(tabName = "analysis",
h2("Detailed Analysis")
)
)
)
)
Latest Trends (2025)
- Golem/Rhino Frameworks: Standardization of production development
- Enhanced Async Processing: Parallel processing with promises/future
- WebAssembly Integration: Faster client-side processing
- Reactive Caching: More efficient computation management
- AI Assist Features: Automatic UI generation and code completion
Summary
Shiny maintains its important position as the first choice for building web applications in R in 2025. Its greatest strength is the reactive programming model, which enables data scientists to create interactive applications without web expertise. With the maturation of enterprise tools like Golem, Rhino, and shinytest2, it has become capable of full-scale web application development.