Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

394
Views
I want to create a draggable modalDialog in shiny

I want to create a draggable shiny::modalDialog() with just shiny and JS/jQuery and without other packages like shinyjqui. Following the example from here it should be easily achievable with the jQuerys .draggable sine the modalDialog created when clicking on the actionButton has bootstrap class modal, but somehow it does not work. Does anybody has some advice?

library(shiny)
library(bslib)

ui = fluidPage(theme = bs_theme(version = 5),

  div(style = "margin: 4rem; display: flex; justify-content: center;",
  div(    
  actionButton(inputId = "action", label = "open modal"))),
  
  
  tagList(
  tags$script(HTML('$(".modal").draggable({
                      handle: ".modal-header"
                      });')))
)

server = function(input, output, session){
 
  observeEvent(input$action, {
    
    showModal(
      modalDialog(
        title = "Modal", easyClose = T))
    })
}

shinyApp(ui, server)
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

If you don't want to use shinyjqui you still need to add jQuery UI to use .draggable. Additionally to the missing JS library, your code doesn't work because you can not enable draggable functionality to an element that doesn't exist yet. You need to add the JS code just after the creation of the modal inside showModal.

library(shiny)
library(bslib)

ui = fluidPage(theme = bs_theme(version = 5),
   tags$head(tags$script(src="https://code.jquery.com/ui/1.13.0/jquery-ui.js")),
   div(style = "margin: 4rem; display: flex; justify-content: center;",
       div(    
         actionButton(inputId = "action", label = "open modal"))
       )
)

server = function(input, output, session){
  
  observeEvent(input$action, {
    
    showModal(
      tagList(
        modalDialog(title = "Modal", easyClose = T),
        tags$script(HTML('$(".modal").draggable({
                      handle: ".modal-header"
                      });'))
      )
    )
  })
}

shinyApp(ui, server)

It is still possible to use only JS as is described here.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!