I am creating a shiny app that contains a DT data table that allows the user to select the columns to be displayed as there are many fields.
At the moment, the checkbox area is looking like this:
but I would like for it to look more neat and orderly, and arranged in two subgroups: "Upper case" and "Lower case" across multiple columns.
How do I go about doing this?
My code:
library(shiny)
library(DT)
# Create data frame
column_names <- c(toupper(letters[1:26]),tolower(letters[1:26]))
df <- data.frame(replicate(length(column_names),sample(0:1,1000,rep=TRUE)))
# assign column names
colnames(df) = column_names
ui <- fluidPage(
checkboxGroupInput(
"column_selection",
h3("Select fields to display"),
choices = column_names,
inline = TRUE,
selected = c('A','B','C')
),
DT::dataTableOutput("alphabet")
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$alphabet <- DT::renderDT({
columns = column_names
if (!is.null(input$column_selection)) {
columns = input$column_selection
}
datatable(
df[, columns, drop = FALSE],
class = "row-border hover stripe",
rownames = FALSE
)
})
}
# Run the application
shinyApp(ui = ui, server = server)