Moveable multiple Items in R Shiny boxes - something similar to attached screenshot

后端 未结 2 1617
囚心锁ツ
囚心锁ツ 2021-01-28 13:56

I am trying to build a shiny application where I am trying to build a functionality similar to below screenshot:-

I have build something similar using Shinyjqui

2条回答
  •  面向向阳花
    2021-01-28 14:22

    This is just a proof of concept using DT package. Multiple items can be selected from either side and moved over to the other.

    I do not intend to spend time on making this pretty but it should be possible using DT options and css. Lastly, it can be easily reused by packaging in a module.

    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 -

    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)
    

    App Snapshot -

提交回复
热议问题