Easy web applications in R
Shiny is an open source R package that provides an elegant and powerful web framework for building web applications using R. Shiny helps you turn your analyses into interactive web applications without requiring HTML, CSS, or JavaScript knowledge.
Want to build your own Shiny apps?
Interact. Analyze. Communicate.
Take a fresh, interactive approach to telling your data story with Shiny. Let users interact with your data and your analysis. And do it all with R.
Shiny is an R package that makes it easy to build interactive web apps straight from R. You can host standalone apps on a webpage or embed them in R Markdown documents or build dashboards. You can also extend your Shiny apps with CSS themes, htmlwidgets, and JavaScript actions.
Here is a Shiny app
Shiny apps are easy to write. No web development skills are required.
Google Trend Index
The Google Travel Index tracks queries related to airlines, hotels, beach, southwest, las vegas, flights, etc. The index is set to 1.0 on January 1, 2004 and is calculated only for US search traffic.
Description
Shiny comes with a variety of built in input widgets. With minimal syntax it is possible to include widgets like the ones shown on the left in your apps:
# Select type of trend to plot
selectInput(inputId = "type", label = strong("Trend index"),
choices = unique(trend_data$type),
selected = "Travel")
# Select date range to be plotted
dateRangeInput("date", strong("Date range"),
start = "2007-01-01", end = "2017-07-31",
min = "2007-01-01", max = "2017-07-31")
Displaying outputs is equally hassle-free:
mainPanel(
plotOutput(outputId = "lineplot", height = "300px"),
textOutput(outputId = "desc"),
tags$a(href = "https://www.google.com/finance/domestic_trends",
"Source: Google Domestic Trends", target = "_blank")
)
Build your plots or tables as you normally would in R, and make them reactive with a call to the appropriate render function:
output$lineplot <- renderPlot({
plot(x = selected_trends()$date, y = selected_trends()$close, type = "l",
xlab = "Date", ylab = "Trend index")
})
Want to find out how we built the Google Trend Index app shown on the left? See the next tab for the complete source code.
app.R
# Load packages
library(shiny)
library(shinythemes)
library(dplyr)
library(readr)
# Load data
trend_data <- read_csv("data/trend_data.csv")
trend_description <- read_csv("data/trend_description.csv")
# Define UI
ui <- fluidPage(theme = shinytheme("lumen"),
titlePanel("Google Trend Index"),
sidebarLayout(
sidebarPanel(
# Select type of trend to plot
selectInput(inputId = "type", label = strong("Trend index"),
choices = unique(trend_data$type),
selected = "Travel"),
# Select date range to be plotted
dateRangeInput("date", strong("Date range"), start = "2007-01-01", end = "2017-07-31",
min = "2007-01-01", max = "2017-07-31"),
# Select whether to overlay smooth trend line
checkboxInput(inputId = "smoother", label = strong("Overlay smooth trend line"), value = FALSE),
# Display only if the smoother is checked
conditionalPanel(condition = "input.smoother == true",
sliderInput(inputId = "f", label = "Smoother span:",
min = 0.01, max = 1, value = 0.67, step = 0.01,
animate = animationOptions(interval = 100)),
HTML("Higher values give more smoothness.")
)
),
# Output: Description, lineplot, and reference
mainPanel(
plotOutput(outputId = "lineplot", height = "300px"),
textOutput(outputId = "desc"),
tags$a(href = "https://www.google.com/finance/domestic_trends", "Source: Google Domestic Trends", target = "_blank")
)
)
)
# Define server function
server <- function(input, output) {
# Subset data
selected_trends <- reactive({
req(input$date)
validate(need(!is.na(input$date[1]) & !is.na(input$date[2]), "Error: Please provide both a start and an end date."))
validate(need(input$date[1] < input$date[2], "Error: Start date should be earlier than end date."))
trend_data %>%
filter(
type == input$type,
date > as.POSIXct(input$date[1]) & date < as.POSIXct(input$date[2]
))
})
# Create scatterplot object the plotOutput function is expecting
output$lineplot <- renderPlot({
color = "#434343"
par(mar = c(4, 4, 1, 1))
plot(x = selected_trends()$date, y = selected_trends()$close, type = "l",
xlab = "Date", ylab = "Trend index", col = color, fg = color, col.lab = color, col.axis = color)
# Display only if smoother is checked
if(input$smoother){
smooth_curve <- lowess(x = as.numeric(selected_trends()$date), y = selected_trends()$close, f = input$f)
lines(smooth_curve, col = "#E6553A", lwd = 3)
}
})
# Pull in description of trend
output$desc <- renderText({
trend_text <- filter(trend_description, type == input$type) %>% pull(text)
paste(trend_text, "The index is set to 1.0 on January 1, 2004 and is calculated only for US search traffic.")
})
}
# Create Shiny object
shinyApp(ui = ui, server = server)
Ready to share the applications you built?
Put Shiny Web Apps Online
RStudio lets you put shiny web applications and interactive documents online in the way that works best for you.
For Shiny applications, consider Shiny Server or Shiny Server Pro, which adds enterprise grade scaling, security, and admin features to the basic open source edition.
If you prefer for us to host your Shiny applications, one of our shinyapps.io plans is sure to work for you.
When you’re ready, RStudio Connect is a new publishing platform for all the work your teams create in R. Share Shiny applications, R Markdown reports, dashboards, plots, APIs, and more in one convenient place. Use push-button publishing from the RStudio IDE, scheduled execution of reports, and flexible security policies to bring the power of data science to your entire enterprise.
Don’t want to stand up your own server?
Share your Shiny applications online!
Deploy your Shiny applications on the Web in minutes with shinyapps.io.
Easy to Use
Deploying your Shiny applications could not be easier. You don’t need to own a server or know how to configure a firewall to deploy and manage your applications in the cloud. No hardware, installation, or annual purchase contract required.
Secure
Shinyapps.io is secure-by-design. Each Shiny application runs in its own protected environment and access is always SSL encrypted. Standard and Professional plans offer user authentication, preventing anonymous visitors from being able to access your applications. Users are required to authenticate through one of the supported systems which currently include Google, GitHub, or a shinyapps.io account.
Scalable
We bring our IT team so you won’t have to bring yours. Be confident your compute resources will scale effortlessly as your Shiny applications and users increase. You can also tune the performance of your applications by controlling the resources available to them. This includes the ability to run multiple R processes in a given instance, along with the ability to add additional instances to increase your application performance even further. Shinyapps can scale to meet any workload.
Documentation
See the shinyapps.io user guide for instructions on how to use shinyapps.io.
New to Shiny? Check out the Shiny Dev Center, where you can find documentation, tutorials and examples for building Shiny applications.
Community Support
The best place to get help with shinyapps.io is the Shinyapps users mailing list.
If you’re having difficulties with shinyapps, feel free to ask questions there.
Premium Support
Customers with Basic, Standard or Pro subscriptions can get direct access to our support engineers by opening a case on the RStudio Support site.
Questions are answered from 9AM – 5PM(EST) Monday – Friday.
© Copyright 2000-2023 COGITO SOFTWARE CO.,LTD. All rights reserved