I am facing an issue with my Shiny app, where users can select a number of textInput
boxes based on a specified numericInput
value. This same numeric input also determines the number of checkbox pairs displayed. The marked checkboxes should determine which list each textInput
entry is added to. Currently, the checkboxes are displayed vertically, but I want to change this layout to make them appear side by side horizontally. I have attempted to achieve this using CSS without success. Is there a way to rearrange the checkboxes using CSS or through another method? I am aware that it is possible to use checkboxGroupInput
and set inline=TRUE
for this purpose, but in my case, I need each checkbox to direct the corresponding textInput
entries to separate lists.
If anyone has any suggestions or ideas on how to tackle this problem, please share.
library(shiny)
library(shinyWidgets)
library(htmlwidgets)
########## User interface ##########
ui = fluidPage(
navbarPage("",
#### Tab Panel 3 ####
tabPanel("",
fluidRow(
sidebarPanel(
####Conditions information####
#Determine the number of conditions to be labelled
numericInput("num_conds",
label = "Conditions",
min = 1,
max = 96,
value = 1),
br(),
h5(helpText("Changing the number of experimental conditions will erase all designated colors and conditions.")),
helpText("control checkbox"),
verbatimTextOutput("ctls_checked"),
helpText('normalizing control checkbox'),
verbatimTextOutput("norm_ctls_checked")
),
mainPanel(
tags$style('
.shiny-options-group{
margin-top: 5px !important;}
.
'),
column(4, "",
uiOutput("boxes_conds")
), #close condition columns
column(4, "",
uiOutput("control_checkbox"),
),
),
), #close fluidrow
), #End panel 3
) #close navbarpage
)#close ui, fluidpage
########## Server logic #########
server = function(input, output, session) {
#### Page 3: Conditions ####
#Number output for number of conditions
output$value <- renderPrint({ input$num_conds })
#Experimental condition boxes for UI text input
output$boxes_conds <- renderUI({
num_conds <- as.integer(input$num_conds)
lapply(1:num_conds, function(i) {
cond_names <- textInput(paste0("condID", i),
label = paste0("Treatment/ Condition ", i),
placeholder = "Enter condition...")
})
})
output$control_checkbox <- renderUI({
num_conds <- as.integer(input$num_conds)
lapply(1:num_conds, function(i) {
div(
checkboxInput(paste0("CTLcheckbox", i),
label = paste0("Control ", i),
value = FALSE),
checkboxInput(paste0("normCTLcheckbox", i),
label = paste0("Normalizing control ", i),
value = FALSE),
style = 'padding-bottom: 7.62px;'
)
})
})
#verification list for the controls, positive/mut or negative/WT
controls_list <- list()
controls <- reactive({
num_conds <- as.integer(input$num_conds)
lapply(1:num_conds, function(i) {
if(input[[paste0('CTLcheckbox', i)]] == TRUE)
controls_list <- input[[paste0('condID', i)]]
})
})
controls_coll <- reactive({ strsplit(paste0(unlist(controls(), recursive = FALSE), collapse = ','), ",") })
output$ctls_checked <- renderPrint({
controls_coll()
})
#verification list for the normalized controls list
normalized_controls_list <- list()
normalized_controls <- reactive({
num_conds <- as.integer(input$num_conds)
lapply(1:num_conds, function(i) {
if(input[[paste0('normCTLcheckbox', i)]] == TRUE)
controls_list <- input[[paste0('condID', i)]]
})
})
normalized_controls_coll <- reactive({ strsplit(paste0(unlist(normalized_controls(), recursive = FALSE), collapse = ','), ",") })
output$norm_ctls_checked <- renderPrint({
normalized_controls_coll()
})
} # close server
shinyApp(ui = ui, server = server)