Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R shiny select variable based on checkboxGroupInput

Tags:

r

shiny

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.

like image 691
Yoki Avatar asked Mar 27 '26 13:03

Yoki


2 Answers

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]
    })
  }
))
like image 134
Julien Navarre Avatar answered Mar 29 '26 03:03

Julien Navarre


"variable" is supposed to be "date" since this is the control that you are referencing in the UI part, as in:

checkboxGroupInput( "date", "Variable:",
                 choices = names ,selected = names
)
like image 20
ctbrown Avatar answered Mar 29 '26 02:03

ctbrown



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!