Last active
April 13, 2022 14:16
-
-
Save aagarw30/fb054a04cc34526b9dddad4981ef2eb1 to your computer and use it in GitHub Desktop.
Choose plots and display using radio button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
ui <- fluidPage( | |
radioButtons(inputId = "plot_type" , label = "Select the plot", choices = c("scatter", "bar", "hist" )), | |
plotOutput("myplot") | |
) | |
server <- function(input, output, session) { | |
output$myplot <- renderPlot({ | |
if (input$plot_type == "scatter") { | |
ggplot(mtcars, aes(wt, mpg)) + geom_point() | |
} else if (input$plot_type == "bar") { | |
ggplot(mtcars, aes(cyl)) + geom_bar() | |
} | |
else if (input$plot_type == "hist") { | |
ggplot(mtcars, aes(mpg)) + geom_histogram() | |
} | |
}) | |
} | |
shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment