admin管理员组文章数量:1332403
I want to use jquery UI with shiny (not using shinyjqui library). It works perfect when I have a layer and tried to move it using jqueryUI, but when this layer is dynamically generated using insertUI, then, it doesn´t work.
Here is the code:
library(shiny)
ui <- fluidPage(theme = "style.css",
tags$script(src = "jquery-ui.js"),
tags$script(src = "script2.js"),
actionButton("add","Add layer"),
div(class="aux"),
div(id="works",style="width:300px;height:200px;background:red"))
server <- function(input, output, session) {
observeEvent(input$add,{
insertUI(
selector = ".aux",
where="afterEnd",
ui = div(id=paste0("new",input$add),style="width:300px;height:200px;background:blue")
)
})
}
shinyApp(ui, server)
And the js script
$( function() {
$("#works").draggable();
$("#new1").draggable();
});
Thanks!
I want to use jquery UI with shiny (not using shinyjqui library). It works perfect when I have a layer and tried to move it using jqueryUI, but when this layer is dynamically generated using insertUI, then, it doesn´t work.
Here is the code:
library(shiny)
ui <- fluidPage(theme = "style.css",
tags$script(src = "jquery-ui.js"),
tags$script(src = "script2.js"),
actionButton("add","Add layer"),
div(class="aux"),
div(id="works",style="width:300px;height:200px;background:red"))
server <- function(input, output, session) {
observeEvent(input$add,{
insertUI(
selector = ".aux",
where="afterEnd",
ui = div(id=paste0("new",input$add),style="width:300px;height:200px;background:blue")
)
})
}
shinyApp(ui, server)
And the js script
$( function() {
$("#works").draggable();
$("#new1").draggable();
});
Thanks!
Share Improve this question edited Dec 27, 2018 at 12:20 Stéphane Laurent 84.7k18 gold badges137 silver badges256 bronze badges asked Dec 27, 2018 at 11:10 jffjff 3204 silver badges15 bronze badges1 Answer
Reset to default 8That's because #new1
does not exist at the start-up. You have to execute the javascript code after it have been created, with shinyjs::runjs
for example. And use immediate=TRUE
in insertUI
.
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
tags$head(
tags$script(src = "jquery-ui/jquery-ui.min.js"),
tags$script("$(function() {
$('#works').draggable();
})")
),
actionButton("add","Add layer"),
div(class="aux"),
div(id="works",style="width:300px;height:200px;background:red"))
server <- function(input, output, session) {
observeEvent(input$add,{
insertUI(
selector = ".aux",
where="afterEnd",
ui = div(id=paste0("new",input$add), style="width:300px;height:200px;background:blue"),
immediate = TRUE
)
runjs("$('#new1').draggable();")
})
}
shinyApp(ui, server)
本文标签: javascriptShiny with jquery UIStack Overflow
版权声明:本文标题:javascript - Shiny with jquery UI - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742277909a2445540.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论