Created
January 16, 2024 04:54
-
-
Save tomsing1/ea5b7db11631e3e880df50693a932c88 to your computer and use it in GitHub Desktop.
Reordering the levels of categorical variables in a shiny app with shinyjqui
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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