SHARE
TWEET

Untitled

a guest Jun 17th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library(shiny)
  2. shinyApp(ui = fluidPage(
  3.   sidebarPanel(
  4.     selectInput(inputId = "dropdown", label = "Select data set:",
  5.                 choices = c("iris", "mtcars"), selected = "iris")
  6.   ),
  7.  
  8.   mainPanel(fluidPage(
  9.     fluidRow(plotOutput("plot"),
  10.              actionButton("color", "Color"))
  11.   ))
  12. ), server = function(input, output) {
  13.   get_data <- reactive({
  14.     if(input$dropdown == "iris") {
  15.       return(list(dat = iris, x = "Sepal.Length", color = "Species"))
  16.     } else {
  17.       return(list(dat = mtcars, x = "mpg", color = "cyl"))
  18.     }
  19.   })
  20.   output$plot <- renderPlot({
  21.     dat <- get_data()
  22.     return(plot(dat$dat[, dat$x]))
  23.   })
  24.  
  25.   observeEvent(input$color, {
  26.     output$plot <- renderPlot({
  27.       dat <- get_data()
  28.       return(plot(dat$dat[, dat$x], col = dat$dat[, dat$color]))
  29.     })
  30.   })
  31. })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top