R Shiny 盒子中的可移动多个项目 - 类似于附加的屏幕截图 [英] Moveable multiple Items in R Shiny boxes - something similar to attached screenshot

查看:31
本文介绍了R Shiny 盒子中的可移动多个项目 - 类似于附加的屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个闪亮的应用程序,我正在尝试构建类似于以下屏幕截图的功能:-

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

我已经使用 Shinyjqui/sortable 构建了类似的东西,但我想在移动项目之前允许多选.请让我知道是否有人构建/开发过类似的东西?

I have build something similar using Shinyjqui/sortable but I want to allow multi select prior to moving the items. Please let me know if anyone has built/worked on something similar?

以下是我使用shinyjqui"包创建的示例:-

Below is an example that I have created using "shinyjqui" package:-

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 包的概念证明.可以从任一侧选择多个项目并将其移至另一侧.

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

我不打算花时间让它变得漂亮,但应该可以使用 DT 选项和 css.最后,它可以通过打包在模块中轻松重用.

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.

用户界面 -

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)

应用快照 -

这篇关于R Shiny 盒子中的可移动多个项目 - 类似于附加的屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆