Automatically genrates select inputs for all factor columns in a dataframe.

autoinput_categorical(.df)

Arguments

.df

Dataframe with N variables (one or more should be factor)

Value

Select input for categorical variables

Details

Based on the factor columns on a dataframe, this function generates all the select inputs. The possible values correspond to the levels in each factor column.

Examples

## Only run this example in interactive R sessions
if (interactive()) {
library(shiny)
library(shinymatic)
load('data/customers.rda')
ui <- fluidPage(
  h3('UI (inputs)'),
  autoinput_categorical(.df = customers),
  h3('Server (output)'),
  verbatimTextOutput(outputId = 'values')
)
server <- function(input, output) {
  output$values <- reactive({
    vars_cat <- names(customers)[sapply(customers, is.factor)]
    paste0(sapply(
      vars_cat,
      FUN = function(i)
        paste(i, "=", input[[i]])
    ),
    collapse = '\n')
  })
}
shinyApp(ui = ui, server = server)
}
#> Warning: cannot open compressed file 'data/customers.rda', probable reason 'No such file or directory'
#> Error in readChar(con, 5L, useBytes = TRUE): cannot open the connection