jeudi 29 septembre 2016

R Shiny : how to use checkboxGroupInput values for a search in a table?

I'm a beginner on R et Shiny.

For example, I've added the variable "Group" to the data frame "mtcars" in characters format. Now I have 3 groups of cars : "1", "2" and "3", depending on the "mpg" level of each car.

I have coded that for ui :

library(shiny)

ui <- fluidPage(
checkboxGroupInput("dynamic", "Variables to show:",
                 c("Group 1" = "1",
                   "Group 2" = "2",
                   "Group 3" = "3")),

verbatimTextOutput("input_type_text")

)

And that for server :

server <- function(input, output) {
output$data <- renderTable({
mtcars[, c("Group", input$variable), drop = FALSE]
}, rownames = TRUE)

output$input_type_text <- renderText({input$dynamic})

} 

How could I put a second TextOutput box which shows the number of cars of the group(s) I have selected in the checkboxGroupInput. Of course, if I select 2 groups, the TextOutput box will show the number of cars of these selected groups.

Please how can I do that ?

Sorry for my English.

Thank you very much to everybody.




Aucun commentaire:

Enregistrer un commentaire