R Shiny 盒子中的可移动多个项目 - 类似于附加的屏幕截图
Moveable multiple Items in R Shiny boxes - something similar to attached screenshot
我正在尝试构建一个闪亮的应用程序,我正在尝试构建类似于以下屏幕截图的功能:-
我已经使用 Shinyjqui/sortable 构建了类似的东西,但我想在移动项目之前允许多个 select。如果有人 built/worked 有类似的东西,请告诉我?
下面是我使用 "shinyjqui" 包创建的示例:-
library(shiny)
library(shinyjqui)
attach(mtcars)
ui <- fluidPage(
fluidRow(
column(
width = 12,
uiOutput("OrderInputRender")
)
)
)
server<- function(input,output){
output$OrderInputRender <- renderUI({
fluidRow(
column(width = 6,
orderInput(
"All_Columns",
width = "100%",
label = "Available columns",
items = colnames(mtcars),
style="margin:5px 0 0 0%; overflow: auto; background-color:#DCDCDC; border: 0px solid; padding: 10px; padding: 10px; height:360px;",
connect = c("Segment_Column","Channel_Column")##which dropboxes can interact
)## close of order input
),
column(width = 6,
orderInput(
"Channel_Column",
width = "100%",
label = "Selected Columns",
items = NULL,
style="margin:5px 0 0 0%; overflow: auto; background-color:#DCDCDC; border: 0px solid; padding: 10px; padding: 10px; height:360px;",
connect = c("All_Columns","Segment_Column")##which dropboxes can interact
)## close of order input
)
)
})
}
shinyApp(ui, server)
这只是使用 DT
包的概念证明。可以从任一侧选择多个项目并移至另一侧。
我不打算花时间让它变得漂亮,但使用 DT
选项和 css
应该是可能的。最后,它可以很容易地通过封装在一个模块中被重用。
ui -
library(shiny)
library(DT)
ui <- fluidPage(
br(),
splitLayout(cellWidths = c("45%", "10%", "45%"),
DTOutput("pool"),
list(
br(),br(),br(),br(),br(),br(),br(),
actionButton("add", label = NULL, icon("arrow-right")),
br(),br(),
actionButton("remove", label = NULL, icon("arrow-left"))
),
DTOutput("selected")
)
)
服务器-
server <- function(input, output, session) {
mem <- reactiveValues(
pool = data.frame(LETTERS[1:10]), selected = data.frame()
)
observeEvent(input$add, {
req(input$pool_rows_selected)
mem$selected <- rbind(isolate(mem$selected), mem$pool[input$pool_rows_selected, , drop = F])
mem$pool <- isolate(mem$pool[-input$pool_rows_selected, , drop = F])
})
observeEvent(input$remove, {
req(input$selected_rows_selected)
mem$pool <- rbind(isolate(mem$pool), mem$selected[input$selected_rows_selected, , drop = F])
mem$selected <- isolate(mem$selected[-input$selected_rows_selected, , drop = F])
})
output$pool <- renderDT({
mem$pool
})
output$selected <- renderDT({
mem$selected
})
}
shinyApp(ui, server)
应用程序快照 -
抱歉我的英语不好。
我发现 jQuery 两侧 select 框,我制作了包含此脚本的闪亮演示。
https://www.jqueryscript.net/form/Two-side-Multi-Select-Plugin-with-jQuery-multiselect-js.html
shiny with two side select box jQuery
看起来不错,但存在一个问题,即服务器无法获取仅输入值的选项 selected 在右框中。
# function for make UI HTML
MultiselectHTML <- function(mylist,myname){
paste_sum <- ""
for(i in 1:length(mylist)){
paste_sum <- paste0(paste_sum,"<option value=",i,">",mylist[i],"</option>")
}
# make tag list
tagList(
div(
class = "item_search"
,div(class = "row",
div(class = "col-xs-5",
tags$select(name="from[]",id=myname,class = "form-control",multiple = "multiple",size = "8"
,HTML(paste_sum)
)
)
,div(class = "col-xs-2"
,tags$button(type = "button",class = "btn btn-primary btn-block",id=paste0(myname,"_undo"),"undo")
,tags$button(type = "button",class = "btn btn-block",id=paste0(myname,"_rightAll"),tags$i(class = "glyphicon glyphicon-forward"))
,tags$button(type = "button",class = "btn btn-block",id=paste0(myname,"_rightSelected"),tags$i(class = "glyphicon glyphicon-chevron-right"))
,tags$button(type = "button",class = "btn btn-block",id=paste0(myname,"_leftSelected"),tags$i(class = "glyphicon glyphicon-chevron-left"))
,tags$button(type = "button",class = "btn btn-block",id=paste0(myname,"_leftAll"),tags$i(class = "glyphicon glyphicon-backward"))
,tags$button(type = "button",class = "btn btn-warning btn-block",id=paste0(myname,"_redo"),"redo")
)
,div(class = "col-xs-5"
,tags$select(name="to[]",id=paste0(myname,"_to"), class="form-control" ,size="8", multiple="multiple")
)
)
)
,br()
)
}
ui <- fluidPage(
tags$head(includeScript("www/multiselect.js"))
,tags$script(HTML(
'jQuery(document).ready(function($) {
$("#multiselect1").multiselect({
search: {
left: \'<input type="text" name="q" class="form-control" placeholder="Search..." />\',
right: \'<input type="text" name="q" class="form-control" placeholder="Search..." />\',
},
fireSearch: function(value) {
return value.length >= 1;
}
});
});
')
)
,MultiselectHTML(c("a","b","c","d","e"),"multiselect1")
,h5("Selected List :")
,textOutput("mselect")
)
server <- function(input, output, session) {
output$mselect <- renderText({input$multiselect1_to})
}
shinyApp(ui = ui,server = server)
我正在尝试构建一个闪亮的应用程序,我正在尝试构建类似于以下屏幕截图的功能:-
我已经使用 Shinyjqui/sortable 构建了类似的东西,但我想在移动项目之前允许多个 select。如果有人 built/worked 有类似的东西,请告诉我?
下面是我使用 "shinyjqui" 包创建的示例:-
library(shiny)
library(shinyjqui)
attach(mtcars)
ui <- fluidPage(
fluidRow(
column(
width = 12,
uiOutput("OrderInputRender")
)
)
)
server<- function(input,output){
output$OrderInputRender <- renderUI({
fluidRow(
column(width = 6,
orderInput(
"All_Columns",
width = "100%",
label = "Available columns",
items = colnames(mtcars),
style="margin:5px 0 0 0%; overflow: auto; background-color:#DCDCDC; border: 0px solid; padding: 10px; padding: 10px; height:360px;",
connect = c("Segment_Column","Channel_Column")##which dropboxes can interact
)## close of order input
),
column(width = 6,
orderInput(
"Channel_Column",
width = "100%",
label = "Selected Columns",
items = NULL,
style="margin:5px 0 0 0%; overflow: auto; background-color:#DCDCDC; border: 0px solid; padding: 10px; padding: 10px; height:360px;",
connect = c("All_Columns","Segment_Column")##which dropboxes can interact
)## close of order input
)
)
})
}
shinyApp(ui, server)
这只是使用 DT
包的概念证明。可以从任一侧选择多个项目并移至另一侧。
我不打算花时间让它变得漂亮,但使用 DT
选项和 css
应该是可能的。最后,它可以很容易地通过封装在一个模块中被重用。
ui -
library(shiny)
library(DT)
ui <- fluidPage(
br(),
splitLayout(cellWidths = c("45%", "10%", "45%"),
DTOutput("pool"),
list(
br(),br(),br(),br(),br(),br(),br(),
actionButton("add", label = NULL, icon("arrow-right")),
br(),br(),
actionButton("remove", label = NULL, icon("arrow-left"))
),
DTOutput("selected")
)
)
服务器-
server <- function(input, output, session) {
mem <- reactiveValues(
pool = data.frame(LETTERS[1:10]), selected = data.frame()
)
observeEvent(input$add, {
req(input$pool_rows_selected)
mem$selected <- rbind(isolate(mem$selected), mem$pool[input$pool_rows_selected, , drop = F])
mem$pool <- isolate(mem$pool[-input$pool_rows_selected, , drop = F])
})
observeEvent(input$remove, {
req(input$selected_rows_selected)
mem$pool <- rbind(isolate(mem$pool), mem$selected[input$selected_rows_selected, , drop = F])
mem$selected <- isolate(mem$selected[-input$selected_rows_selected, , drop = F])
})
output$pool <- renderDT({
mem$pool
})
output$selected <- renderDT({
mem$selected
})
}
shinyApp(ui, server)
应用程序快照 -
抱歉我的英语不好。 我发现 jQuery 两侧 select 框,我制作了包含此脚本的闪亮演示。 https://www.jqueryscript.net/form/Two-side-Multi-Select-Plugin-with-jQuery-multiselect-js.html
shiny with two side select box jQuery
看起来不错,但存在一个问题,即服务器无法获取仅输入值的选项 selected 在右框中。
# function for make UI HTML
MultiselectHTML <- function(mylist,myname){
paste_sum <- ""
for(i in 1:length(mylist)){
paste_sum <- paste0(paste_sum,"<option value=",i,">",mylist[i],"</option>")
}
# make tag list
tagList(
div(
class = "item_search"
,div(class = "row",
div(class = "col-xs-5",
tags$select(name="from[]",id=myname,class = "form-control",multiple = "multiple",size = "8"
,HTML(paste_sum)
)
)
,div(class = "col-xs-2"
,tags$button(type = "button",class = "btn btn-primary btn-block",id=paste0(myname,"_undo"),"undo")
,tags$button(type = "button",class = "btn btn-block",id=paste0(myname,"_rightAll"),tags$i(class = "glyphicon glyphicon-forward"))
,tags$button(type = "button",class = "btn btn-block",id=paste0(myname,"_rightSelected"),tags$i(class = "glyphicon glyphicon-chevron-right"))
,tags$button(type = "button",class = "btn btn-block",id=paste0(myname,"_leftSelected"),tags$i(class = "glyphicon glyphicon-chevron-left"))
,tags$button(type = "button",class = "btn btn-block",id=paste0(myname,"_leftAll"),tags$i(class = "glyphicon glyphicon-backward"))
,tags$button(type = "button",class = "btn btn-warning btn-block",id=paste0(myname,"_redo"),"redo")
)
,div(class = "col-xs-5"
,tags$select(name="to[]",id=paste0(myname,"_to"), class="form-control" ,size="8", multiple="multiple")
)
)
)
,br()
)
}
ui <- fluidPage(
tags$head(includeScript("www/multiselect.js"))
,tags$script(HTML(
'jQuery(document).ready(function($) {
$("#multiselect1").multiselect({
search: {
left: \'<input type="text" name="q" class="form-control" placeholder="Search..." />\',
right: \'<input type="text" name="q" class="form-control" placeholder="Search..." />\',
},
fireSearch: function(value) {
return value.length >= 1;
}
});
});
')
)
,MultiselectHTML(c("a","b","c","d","e"),"multiselect1")
,h5("Selected List :")
,textOutput("mselect")
)
server <- function(input, output, session) {
output$mselect <- renderText({input$multiselect1_to})
}
shinyApp(ui = ui,server = server)