【发布时间】:2017-03-22 11:18:24
【问题描述】:
在很多网站上,您都有一个拖放界面来更改列表中元素的顺序。我在 Shiny 中寻找类似的东西。我希望用户能够拖放列表的元素以通过更改顺序来更改优先级。
现在我有一个滥用selectizeInput() 的解决方案。 This works, but it quickly becomes cumbersome when the list of choices becomes larger.
插图:
library(shiny)
shinyApp(
ui = shinyUI({
fluidPage(
title = "Example for ordering objects",
sidebarLayout(
sidebarPanel(uiOutput("selection"),
actionButton('update',"Update")),
mainPanel(
helpText('The order of elements'),
tableOutput('theorder')
)
)
)
}),
server = function(input, output, session) {
values <- reactiveValues(x = c('Item1','Item2','Item3'))
output$selection <- renderUI({
selectizeInput('neworder',
'Select new order',
choices = values$x,
multiple = TRUE)
})
output$theorder <- renderTable(
values$x
)
observeEvent(input$update,{
id <- values$x %in% input$neworder
values$x <- c(input$neworder, values$x[!id])
})
}
)
缺点:要更改列表末尾的顺序,用户必须以正确的顺序选择整个列表。一个错误,他必须重新开始。
Wishlist:一个闪亮的小部件(可能来自另一个包),最好是拖放,可以使这种操作更方便。
【问题讨论】:
标签: r drag-and-drop shiny