我想用insertUI()
创建一个可拖动的Ui对象。多亏了actionButton()
,创建了一个相似的对象,并且可以正常工作。但是,可拖动属性已被删除。
我试图添加一些代码,例如tags$script('$(".draggable").draggable();')
或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:"
)
)
)
)
)
)
)
})
}
答案 0 :(得分:0)
多亏了jqui_draggable()
软件包中的shinyjqui
,我找到了解决方案。
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:"
)
)
)
)
)
)
)
)
})
}