Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(shiny)
- shinyApp(ui = fluidPage(
- sidebarPanel(
- selectInput(inputId = "dropdown", label = "Select data set:",
- choices = c("iris", "mtcars"), selected = "iris")
- ),
- mainPanel(fluidPage(
- fluidRow(plotOutput("plot"),
- actionButton("color", "Color"))
- ))
- ), server = function(input, output) {
- get_data <- reactive({
- if(input$dropdown == "iris") {
- return(list(dat = iris, x = "Sepal.Length", color = "Species"))
- } else {
- return(list(dat = mtcars, x = "mpg", color = "cyl"))
- }
- })
- output$plot <- renderPlot({
- dat <- get_data()
- return(plot(dat$dat[, dat$x]))
- })
- observeEvent(input$color, {
- output$plot <- renderPlot({
- dat <- get_data()
- return(plot(dat$dat[, dat$x], col = dat$dat[, dat$color]))
- })
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement