Align checkBoxGroup Enter vertically and horizontally

In a similar message ( How to align the checkboxGroupInput group in R Shiny ), the flags are only aligned vertically (as in my example) or only horizontally ( R The brilliant checkboxGroupInput display is horizontal ). I wonder if there is a way to do this in both senses (when in columns).

library(shiny) examplesubset<-read.table(text=" elements locations element_One A,M,P,R element_Two A,B,C,M,P,E,I element_Three G,M,T,F,O,H,A,B,C,D" , header=TRUE, stringsAsFactors=FALSE) examplesubset$elements<-as.factor(examplesubset$elements) ui<-fluidPage( tags$head(tags$style(HTML(" .multicol { -webkit-column-count: 3; /* Chrome, Safari, Opera */ -moz-column-count: 3; /* Firefox */ column-count: 3; -moz-column-fill: auto; -column-fill: auto; } "))), titlePanel("Panel"), sidebarLayout( sidebarPanel( selectInput("elements", "Select elements:", choices=examplesubset$elements) ) , mainPanel( fluidRow( column(3, uiOutput("checkboxesui") )))) ) server<-function(input, output,session) { elementsselected<-reactive({ sp<-examplesubset[examplesubset$elements==input$elements,] sp<-droplevels(sp) }) locationsreactive<- reactive({ j<-as.factor(unique(unlist(strsplit(elementsselected()$locations, ",", fixed = TRUE) ) ) ) j<-droplevels(j) }) output$checkboxesui<-renderUI({ tags$div(align = 'left', class = 'multicol', checkboxGroupInput("locationscheckboxes", "locations", choices=levels(locationsreactive()) , selected=c() ) ) }) } shinyApp(ui = ui, server = server) 

enter image description here

+7
css r shiny
source share
1 answer

The following code should do the trick. You needed to apply CSS columns to the element below where you had them, and then remove the registration from the top and bottom, I also changed the column filling to balanced:

 library(shiny) examplesubset<-read.table(text=" elements locations element_One A,M,P,A,R,T element_Two A,B,C,M,P,E,I,N,S element_Three G,M,T,F,S,V,P" , header=TRUE, stringsAsFactors=FALSE) examplesubset$elements<-as.factor(examplesubset$elements) ui<-fluidPage( tags$head(tags$style(HTML(" .multicol .shiny-options-group{ -webkit-column-count: 3; /* Chrome, Safari, Opera */ -moz-column-count: 3; /* Firefox */ column-count: 3; -moz-column-fill: balanced; -column-fill: balanced; } .checkbox{ margin-top: 0px !important; -webkit-margin-after: 0px !important; } "))), titlePanel("Panel"), sidebarLayout( sidebarPanel( selectInput("elements", "Select elements:", choices=examplesubset$elements) ) , mainPanel( fluidRow( column(3, uiOutput("checkboxesui") )))) ) server<-function(input, output,session) { elementsselected<-reactive({ sp<-examplesubset[examplesubset$elements==input$elements,] sp<-droplevels(sp) }) locationsreactive<- reactive({ j<-as.factor(unique(unlist(strsplit(elementsselected()$locations, ",", fixed = TRUE) ) ) ) j<-droplevels(j) }) output$checkboxesui<-renderUI({ tags$div(align = 'left', class = 'multicol', checkboxGroupInput("locationscheckboxes", "locations", choices=levels(locationsreactive()) , selected=c() ) ) }) } shinyApp(ui = ui, server = server) 

Fixed

Another option is to use CSS flexbox: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

This will solve the problems you described with the order, but you will need to reflect on the size of the shiny-options-group, so that everything is according to your desire, depending on your content. It's probably easier to just reorder your options so that they appear the way you want.

+4
source share

All Articles