1

I'm trying to get the pickerInput dropdown placed in front of the confirmSweetAlert buttons, but using z-index within CSS doesn't appear to work. Any other suggestions?

library(shiny)
library(shinyWidgets)


ui <- fluidPage(
  actionButton(
    inputId = "launch",
    label = "Launch Confirm!"
  )
)

server <- function(input, output, session) {
  
  # Launch sweet alert confirmation
  observeEvent(input$launch, {
    confirmSweetAlert(
      session = session,
      inputId = "test",
      title = "This is a Test!",
      type = "info",
      text = tags$div(
        div(style="position: relative; z-index: 1;", pickerInput(
          inputId = "numbers",
          multiple = TRUE,
          choices = 1:5,
          width = "100%"
        )),
      closeOnClickOutside = FALSE,
      html = TRUE
    ))
  })

}

if (interactive())
  shinyApp(ui, server)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
m.yoshih
  • 59
  • 6

1 Answers1

3

You can use options = pickerOptions(container = "body") in pickerInput to append the select to a specific element, in that case "body" help positioning the menu.

Full example:

library(shiny)
library(shinyWidgets)


ui <- fluidPage(
  actionButton(
    inputId = "launch",
    label = "Launch Confirm!"
  )
)

server <- function(input, output, session) {
  
  # Launch sweet alert confirmation
  observeEvent(input$launch, {
    confirmSweetAlert(
      session = session,
      inputId = "test",
      title = "This is a Test!",
      type = "info",
      text = tags$div(
        pickerInput(
          inputId = "numbers",
          multiple = TRUE,
          choices = 1:5,
          width = "100%",
          options = pickerOptions(container = "body")
        ),
        closeOnClickOutside = FALSE,
        html = TRUE
      ))
  })
  
}

if (interactive())
  shinyApp(ui, server)
Victorp
  • 13,636
  • 2
  • 51
  • 55
  • Thanks so much! Please also see https://community.rstudio.com/t/have-pickerinput-dropdown-placed-in-front-of-confirmsweetalert-buttons/101260/ for another solution. – m.yoshih Apr 09 '21 at 21:15