Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  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. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement