How to create dynamic plots based on checkbox inputs, number of plots should be increased and decreased with respect to the names selected checkbox.
Asked
Active
Viewed 2,167 times
-4
-
1Please read [How to make a great R reproducible example?](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and edit your post according it. Now this question is too broad. – pogibas Jul 12 '18 at 09:35
-
Please provide the code sniping to provide you the answer – Sovik Gupta Jul 12 '18 at 09:39
-
The above provided link is related to R and i'm looking for suggestions for R shiny. Can you provide any similar topics related to R shiny ??? – Dinesh Jul 12 '18 at 09:44
1 Answers
5
You can use library(gridExtra)
and plot several plots depends (grid.arrange
) on how many checkbox you actvated.
library(shiny)
# Define UI for application
ui <- fluidPage(
checkboxGroupInput("variable", "Variables to show:",
c("Cylinders" = "cyl",
"Transmission" = "am",
"Gears" = "gear")),
mainPanel(plotOutput("distPlot"))
)
# Define server logic
server <- function(input, output, session) {
require(gridExtra)
require(ggplot2)
output$distPlot <- renderPlot({
if (length(input$variable) == 0) {
ggplot(data.frame())
} else {
gl <- lapply(input$variable,
function(x) ggplot(mtcars, aes(mtcars[, x])) +
geom_bar() +
xlab(x))
grid.arrange(grobs = gl, nrow = 1)
}
})
}
# Run the application
shinyApp(ui = ui, server = server)

Artem
- 3,304
- 3
- 18
- 41