繁体   English   中英

使用insertUi()的可拖动属性消失

[英]Draggable property dissapear with insertUi()

我想用insertUI()创建一个可拖动的Ui对象。 由于actionButton()已经创建了一个类似的对象,它工作正常。 但是,可拖动的属性已被删除。

我试图添加一些代码,如tags$script('$(".draggable").draggable();') OR tags$script('$(".dragelement").on("dragstart",function(e){e.originalEvent.dataTransfer.setData("Text",e.target.id);});')

但是,它不再起作用了。 有人有想法吗?

以下示例来自http://shiny.rstudio.com/gallery/absolutely-positioned-panels.html

library(shiny)
library(markdown)
### Ui.R
    ui <- fluidPage(
      actionButton("add", "Add UI"),
      absolutePanel(
        bottom = 20, 
        right = 20, 
        width = 300,
        draggable = TRUE,
        wellPanel(
          HTML(
            markdownToHTML(
              fragment.only=TRUE, 
              text=c(
                "This is an absolutePanel that uses `bottom` and `right` attributes.

                    It also has `draggable = TRUE`, so you can drag it to move it around the page.

                    The slight transparency is due to `style = 'opacity: 0.92'`.

                    You can put anything in absolutePanel, including inputs and outputs:"
              )
            )
          ),
          sliderInput("n", "", min=3, max=20, value=5),
          plotOutput("plot2", height="200px")
        )
      )
    )

###Server.R   
    server <- function(input, output, session) {
      observeEvent(input$add, {
        insertUI(
          selector = "#add",
          where = "afterEnd",
          ui =           
            tagList(
              absolutePanel(
                top = 80, 
                right = 20, 
                width = 300,
                draggable = TRUE,
                wellPanel(
                  HTML(
                    markdownToHTML(
                      fragment.only=TRUE, 
                      text=c(
                        "This is an absolutePanel that uses `bottom` and `right` attributes.

                    It also has `draggable = TRUE`, so you can drag it to move it around the page.

                    The slight transparency is due to `style = 'opacity: 0.92'`.

                    You can put anything in absolutePanel, including inputs and outputs:"
                      )
                    )
                  )
                )
              )
            )
        )
      })
    }

由于来自shinyjqui包的jqui_draggable() ,我找到了一个解决方案。

library(shinyjqui)
server <- function(input, output, session) {
  observeEvent(input$add, {
    insertUI(
      selector = "#add",
      where = "afterEnd",
      ui =  
        jqui_draggable(
        tagList(
          absolutePanel(
            top = 80, 
            right = 20, 
            width = 300,
            draggable = TRUE,
            wellPanel(
              HTML(
                markdownToHTML(
                  fragment.only=TRUE, 
                  text=c(
                    "This is an absolutePanel that uses `bottom` and `right` attributes.

                It also has `draggable = TRUE`, so you can drag it to move it around the page.

                The slight transparency is due to `style = 'opacity: 0.92'`.

                You can put anything in absolutePanel, including inputs and outputs:"
                  )
                )
              )
            )
          )
        )
        )
      )
    })
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM