Quiero crear un shiny::modalDialog() arrastrable con solo shiny y JS/jQuery y sin otros paquetes como shinyjqui . Siguiendo el ejemplo de aquí , debería ser fácilmente alcanzable con jQuerys .draggable , ya que el modalDialog creado al hacer clic en el botón de actionButton tiene una clase de arranque modal , pero de alguna manera no funciona. ¿Alguien tiene algún consejo?
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)Si no desea usar shinyjqui , aún necesita agregar jQuery UI para usar .draggable . Además de la biblioteca JS que falta, su código no funciona porque no puede habilitar la funcionalidad arrastrable a un elemento que aún no existe. Debe agregar el código JS justo después de la creación del modal dentro de 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)Todavía es posible usar solo JS como se describe aquí .