ShinyBS Modal in checkbox group

I am using shinyBS::bsModal() to explain the interface elements. It works fine when I put bsButton() behind the checkbox header.

Now I want to put it behind the flags. The first clue might be this answer , where the same is for the tooltip (but my modification does not work).

Minimal example:

 library(shiny) library(shinyBS) ui <- fluidPage( sidebarLayout( sidebarPanel( checkboxGroupInput("qualdim", tags$span("Chekboxoptions", bsButton("modalbt", "?", style = "inverse", size = "extra-small")), c("Option_1" = "Option_1", "Option_2" = "Option_2")) ), mainPanel( bsModal("modalExample", "Modal", "modalbt", size = "large", verbatimTextOutput("helptext"))) ) ) server <- function(input, output) { output$helptext <- renderText({"I can trigger a shinyBS::bsModal() from here, but I want to place two buttons behind `Option_1` and `Option_2`" }) } shinyApp(ui = ui, server = server) 
+3
source share
1 answer

bsModal works anywhere and simply accepts the button id as a trigger. So you only need to make a suitable button inside the checkboxGroup . From the previous question / answer that you linked, you already have a function to get bsButton inside the group input. (Just delete the line where the tooltip was assigned. This is not needed here.)

The code below is copy. I added a few additional bsButton parameters, such as size, style, and identifier ( this is important! It was not important in the related question with tips! ), So you can use the function more, you should use bsButton .

 library(shiny) library(shinyBS) makeCheckboxButton <- function(checkboxValue, buttonId, buttonLabel, size = "default", style = "default"){ size <- switch(size, `extra-small` = "btn-xs", small = "btn-sm", large = "btn-lg", "default") style <- paste0("btn-", style) tags$script(HTML(paste0(" $(document).ready(function() { var inputElements = document.getElementsByTagName('input'); for(var i = 0; i < inputElements.length; i++){ var input = inputElements[i]; if(input.getAttribute('value') == '", checkboxValue, "'){ var button = document.createElement('button'); button.setAttribute('id', '", buttonId, "'); button.setAttribute('type', 'button'); button.setAttribute('class', '", paste("btn action-button", style , size), "'); button.appendChild(document.createTextNode('", buttonLabel, "')); input.parentElement.parentElement.appendChild(button); }; } }); "))) } ui <- fluidPage( sidebarLayout( sidebarPanel( checkboxGroupInput("qualdim", label = "Chekboxoptions", choices = c("Option_1", "Option_2")), makeCheckboxButton("Option_1", "modalbt", "?", size = "extra-small", style = "inverse") ), mainPanel( bsModal("modalExample", "Modal", "modalbt", size = "large", verbatimTextOutput("helptext"))) ) ) server <- function(input, output) { output$helptext <- renderText({"I can trigger a shinyBS::bsModal() from here, but I want to place two buttons behind `Option_1` and `Option_2`" }) } shinyApp(ui = ui, server = server) 
+3
source

All Articles