Yoki Yoki - 25 days ago 10
R Question

R shiny select variable based on checkboxGroupInput

I am using R shiny to develop a interactive analysis tool. Now I want to do classification tree based on variables check in checkboxGroupInput. How can I select that subset of data? THX!

UI:

dateInput("date","Enter date:",value = date),
checkboxGroupInput("variable", "Variable:",
choices = names ,selected = names
)


server I tried, but doesn't work:

dataall <- reactive({
filename <- paste0("dataall_'", input$date, "'.RData")
load(filename)
feature.test[,names(feature.test) %in% input$variable]
})


feature.test is data in loaded file.

Answer

Hard to understand what you want since you don't subset the file you load. What is feature.test ?

Here is a simple example to how to subset a data frame using an input and shiny reactivity :

shiny::runApp(list(
  ui = basicPage(
    selectInput("specy", "Specy", choices = levels(iris$Species)),
    tableOutput("content")
  ),
  server = function(input, output, session) {
    output$content <- renderTable({
      iris[iris$Species == input$specy, ]
    })
  }
))

EDIT ## : Subset by column :

shiny::runApp(list(
  ui = pageWithSidebar(
    headerPanel("Example"),
    sidebarPanel(
      checkboxGroupInput("variable", "Variable:", choices = names(iris))
    ),
    mainPanel(
     tableOutput("content")
    )
  ),
  server = function(input, output, session) {
    output$content <- renderTable({
      if(is.null(input$variable))
        return()

      iris[input$variable]
    })
  }
))