Skip to content

Instantly share code, notes, and snippets.

@tomsing1
Created January 16, 2024 04:54
Show Gist options
  • Save tomsing1/ea5b7db11631e3e880df50693a932c88 to your computer and use it in GitHub Desktop.
Save tomsing1/ea5b7db11631e3e880df50693a932c88 to your computer and use it in GitHub Desktop.
Reordering the levels of categorical variables in a shiny app with shinyjqui
library(palmerpenguins)
library(shiny)
library(shinyjqui)
categories <- colnames(penguins)[vapply(penguins, is.factor, logical(1))]
server <- function(input, output) {
lapply(categories, \(category) {
output[[category]] <- renderPrint({ print(input[[category]]) })
})
}
ui <- fluidPage({
lapply(categories, \(category) {
tagList(
orderInput(category, category, items = levels(penguins[[category]])),
verbatimTextOutput(category)
)
})
})
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment