Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

393
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda