I am usng the following CSS recommended in some other post for my Shiny checkboxGroupInput
, and it mostly works. Produces a grid of checkboxes that are aligned well on the left. But, then, there is quite a bit of misalignment in other columns of the checkbox grid.
tags$head(
tags$style(
HTML(
".checkbox-inline {
margin-left: 0px;
margin-right: 16px;
}
.checkbox-inline+.checkbox-inline {
margin-left: 0px;
margin-right: 16px;
}
"
)
)
),
See below image output. What can I change to make it display in a proper way? Number of items in the check box group varies, and the width of the item also varies.
UPDATE:
Based on the answer below, I am using the following in the Shiny dashboardBody
:
tags$head(
tags$style(
HTML(
".wrapper-grid{
display: grid;
grid-template-columns: repeat(5, 1fr);
grid-template-rows: repeat(2, 1fr);
grid-column-gap: 0px;
grid-row-gap: 0px;
}
"
)
)
)
And, I am using the following in the following for the checkboxGroupInput
, and yet, my misalignment isn’t going away. What am I doing wrong in wrapping this into Shiny?
tags$div(align = 'left', class = 'wrapper-grid', checkboxGroupInput(
inputId = 'myID',
label = 'Select my IDs:',
choices = unique(rl$ID),
selected = unique(rl$ID),
width = '1000px',
inline = TRUE
)
2
Answers
You can use flex or grid.
(check box and label must be in same DIV or something element. and you can control on wrapper element with CSS)
https://codepen.io/sawacrow/pen/mdGxewL
grid generator:
https://cssgrid-generator.netlify.app/
So I think the problem is that you are defining the CSS for the container that contains the group of checkboxes not the actual group of checkboxes which is buried in a few intermediate child containers. I’m sure it’s possible to force the children to take inherit from the div you created, but it’s also easy to just directly use the html element for the check box group inside the div. (should be
#myID > div:nth-child(2)
)All I did was switch
.wrapper-grid
with#myID > div:nth-child(2)
for the CSS you already provided in your question. For whatever reason, with just that, the first checkbox’s left margin is off, so I also had to adjust the margin for just the first checkbox(#myID > div:nth-child(2) > label:nth-child(1)
). Here’s a reproducible example of a shiny that worked for me.I only fixed the first set of checkboxes so the second set is still off. To fix everything at once you can use the checkbox class instead (
.shiny-options-group
).Here’s what it looks like:
(second row intentionally not fixed)