Skip to content

Instantly share code, notes, and snippets.

@aagarw30
Last active April 13, 2022 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aagarw30/fb054a04cc34526b9dddad4981ef2eb1 to your computer and use it in GitHub Desktop.
Save aagarw30/fb054a04cc34526b9dddad4981ef2eb1 to your computer and use it in GitHub Desktop.
Choose plots and display using radio button
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