Javascript 从克隆的shinyjqui对象获取输入$id
这是一个非常具体的例子,我尝试尽可能地配对,但我已经使用带有selectInput框的Javascript 从克隆的shinyjqui对象获取输入$id,javascript,jquery,r,shiny,jquery-ui-droppable,Javascript,Jquery,R,Shiny,Jquery Ui Droppable,这是一个非常具体的例子,我尝试尽可能地配对,但我已经使用带有selectInput框的shinyjqui创建了可拖动的div。问题是,使用input$id可以在原始拖动区域中为我提供selectInput,并且我希望获得拖动到拖放区域中的框的所有input$id 我认为最好的方法是添加JQuery代码,重新分配被删除元素的ID,这样我就可以访问它们的输入——有人知道如何最好地解决这个问题吗 电流输出 使用make.unique为每个input$dest_order$text指定一个数字,我希望随
shinyjqui
创建了可拖动的div。问题是,使用input$id
可以在原始拖动区域中为我提供selectInput,并且我希望获得拖动到拖放区域中的框的所有input$id
我认为最好的方法是添加JQuery代码,重新分配被删除元素的ID,这样我就可以访问它们的输入——有人知道如何最好地解决这个问题吗
电流输出
使用make.unique
为每个input$dest_order$text
指定一个数字,我希望随后可以动态创建与之匹配的selectInput ID,这样我就可以使用粘贴到input
列中的内容来获取实际的select值?这可能不是最好的方法,我愿意接受完全不同的建议!!!
期望输出
我的策略是为Put Herediv
中的每个选择创建唯一的ID,这样我就可以从右侧列表中获得input$dropdown.1
,input$dropdown.2
等,而不是只使用左手选择的input$dropdown
,但是也许有一种方法可以使用JQuery在Put Here
框中获取所有选中的选项,而不需要弄乱ID?
库(闪亮)
图书馆(shinyjs)
图书馆(shinyjqui)
这是一个有趣的问题。可能是答案的一部分。我无法将其应用于您闪亮的应用程序,但可能会有所帮助。哇,这太有帮助了,谢谢@TimTeaFan!我将尝试使代码适应我的用例!如果你找到了答案,请在你的帖子上贴一个答案,我想知道你是如何解决的;)
library(shiny)
library(shinyjs)
library(shinyjqui)
BLOCKS <- c("dropdown", "Block")
Blocks <- function(data, name)
{
div(style = "
text-align: center;
font-size: 12px;
background-color: #A9A9A9;
border-radius: 10px;
color: black; margin-bottom: 5px;
min-width: 80px;
",
drag = name,
id = name,
class = "cloned",
if (name == "dropdown") {
# how do I abstractly make the ids ttest_1 and ttest_2
# based on the occurances in the vector?
selectInput(name, "Dropdown", choices = c("1", "2", "3"), selectize = FALSE)
} else {
name
}
)
}
ui <- fluidPage(
tags$head(
tags$script(
"$( function() {
$( '.delete_dropped' ).droppable({
drop: function(e, ui) {
$(ui.helper).remove();
}
})
});
$( function() {
$( '.cloned' ).draggable({
helper: 'clone',
connectToSortable: '#dest',
drop: function(e, ui) {
$(ui.helper).remove();
}
})
});"
)),
sidebarPanel(
fluidRow(column(6, h5("Drag"),
jqui_sortable(div(id = "source", class="delete_dropped",
lapply(BLOCKS, Blocks, data = BLOCKS),
style = "border: 1px solid black;padding:10px;min-height:50px;"),
options = list(connectWith = "#dest"))),
column(6, h5("Put Here"),
jqui_sortable(div(id = "dest", style = "border: 1px solid black;padding:10px;min-height:50px"),
options = list(connectWith = "#source")))
)),
mainPanel(tableOutput("debug"))
)
server <- function(input, output, session) {
output$debug <- renderTable({
# print the block text and make unique
# maybe I can use these unique names to rename the ids of the selectInputs
# then I can input[["Dropdown"]], input[["Dropdown.1"]], etc etc to get the selected option?
t <- data.frame( id = make.unique(unlist(input$dest_order$text)))
t$input <- ifelse(grepl('^Block', t$id), NA, paste0("input[[", t$id, "]]"))
t
})
}
shinyApp(ui, server)