如何使模态对话框在使用renderUI()呈现时可拖动?

x8diyxa7  于 2023-04-18  发布在  其他
关注(0)|答案(1)|浏览(115)

我试图在下面的代码中使模态对话框可拖动,但还没有运气。模态对话框是通过点击python图标触发的。我需要一个可拖动的框,因为完整应用程序中的解释性文本很长,大多数用户都希望移动对话框,以便他们可以看到正在解释的情节。在下面的代码中,我试图创建一个可拖动的模态对话框的所有行都用###标记,哪些行取自I want to create a draggable modalDialog in shiny,但在我的情况下不起作用。它可能不适用于我,因为我使用renderUI()。在我的情况下,有解决方案吗?
验证码:

library(shiny)

ui <- fluidPage(
  tags$head(tags$script(src="https://code.jquery.com/ui/1.13.0/jquery-ui.js")), ###
  selectInput("distSelect","Select distribution:",c("Weibull","Gamma")),
  uiOutput("plotHeader"),
  fluidRow(plotOutput("plot"))
)

server <- function(input, output, session) {
  
  output$plot <- renderPlot({curve(pweibull(x,shape=1.5,scale=1/0.03,lower.tail=F),from=0,to=80)})

  output$plotHeader <- renderUI({
    fluidPage(
      paste(input$distSelect,"Distribution"), 
      div( ###
        style = "margin: 4rem; display: flex;", ###
        div(   ###
          tags$button(
            id = "explainBtn",
            class = "btn action-button",
            tags$img(src = "https://images.plot.ly/language-icons/api-home/python-logo.png")
          )
        ) ###
      ) ###
    )
  })
  
  observeEvent(input$explainBtn, {
    showModal(
      tagList( ###
        modalDialog(if(input$distSelect == "Weibull"){"Weibull..."}),
        tags$script(HTML('$(".modal").draggable({ ###
                      handle: ".modal-header" ###
                      });')) ###
        )
      ) ###
  })
  
}
shinyApp(ui, server)
ocebsuys

ocebsuys1#

请检查shinyjqui::jqui_draggable

library(shiny)
library(shinyjqui)

ui <- fluidPage(
  selectInput("distSelect","Select distribution:",c("Weibull","Gamma")),
  uiOutput("plotHeader"),
  fluidRow(plotOutput("plot"))
)

server <- function(input, output, session) {
  
  output$plot <- renderPlot({curve(pweibull(x,shape=1.5,scale=1/0.03,lower.tail=F),from=0,to=80)})
  
  output$plotHeader <- renderUI({
    fluidPage(
      paste(input$distSelect,"Distribution"), 
      div( ###
        style = "margin: 4rem; display: flex;", ###
        div(   ###
          tags$button(
            id = "explainBtn",
            class = "btn action-button",
            tags$img(src = "https://images.plot.ly/language-icons/api-home/python-logo.png")
          )
        ) ###
      ) ###
    )
  })
  
  observeEvent(input$explainBtn, {
    showModal(
      jqui_draggable(modalDialog(if(input$distSelect == "Weibull"){"Weibull..."}))
      )
  })
  
}
shinyApp(ui, server)

PS:此外,您可能需要检查库(cicerone)。

相关问题