많은 웹 사이트에서 목록의 요소 순서를 변경하는 끌어서 놓기 인터페이스가 있습니다. 나는 Shiny에서 비슷한 것을 찾고있다. 사용자가 순서를 변경하여 목록의 요소를 끌어다 놓아 우선 순위를 변경할 수 있기를 바랍니다.벡터의 요소 순서를 변경하는 반짝이는 도구
바로 지금 나는 남용한 해결책이 있습니다 selectizeInput()
. 이 방법은 효과가 있지만 선택 목록이 커지면 신속하게 성가 시게됩니다.
그림 :
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])
})
}
)
단점 : 목록의 끝에서 순서를 변경하려면 사용자가 올바른 순서로 전체 목록을 선택할 수 있습니다. 하나의 실수와 그는 다시 처음부터 다시 시작해야합니다.
위시리스트 : 이런 종류의 작업을보다 편리하게 만들 수있는 반짝이는 위젯 (다른 패키지에서 가능). 드래그 앤 드롭이 바람직합니다.
환상적이며 멋지게 작동합니다. 정말 Javascript에 관해서 두 가지를 배워야합니다 :-) –