Shiny Apps

Advanced RShinyFree Lesson

Advertisement

Introduction

Shiny creates interactive web applications from R. It allows users to interact with data without programming.

Basic Structure

library(shiny)

ui <- fluidPage(
  titlePanel("My App"),
  sidebarLayout(
    sidebarPanel(
      sliderInput("num", "Number:", 1, 100, 50)
    ),
    mainPanel(
      plotOutput("plot")
    )
  )
)

server <- function(input, output) {
  output$plot <- renderPlot({
    hist(rnorm(1000, mean = input$num))
  })
}

shinyApp(ui, server)

Reactive Expressions

server <- function(input, output) {
  data <- reactive({
    df %>% filter(x > input$threshold)
  })
  
  output$plot <- renderPlot({
    ggplot(data(), aes(x, y)) + geom_point()
  })
}

Widgets

selectInput("var", "Variable:", choices = names(df))
checkboxInput("show", "Show legend", TRUE)
radioButtons("dist", "Distribution:", c("Normal", "Uniform"))
dateInput("date", "Date:")

Summary

Shiny builds interactive apps. Use it for data exploration and sharing results.

Advertisement

Need Expert R Programming Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement