inst/apps/sortable/app.R

## Example shiny app with bucket list
#remotes::install_github("rstudio/sortable")

library(shiny)
library(sortable)


ui <- fluidPage(
  tags$head(
    tags$style(HTML(".bucket-list-container { min-height: 10px; }"))
  ),

  fluidRow(
    column(
      width = 12,
      bucket_list(
        header = " ",
        group_name = "bucket_list_group_1",
        orientation = "horizontal",
        add_rank_list(
          text = "Drag from here",
          labels = list(
            "row1",
            "row2",
            "row3"
          ),
          input_id = "rank_list_1"
        ),
        add_rank_list(
          text = "Drag from here",
          labels = list(
            "agg1",
            "agg2",
            "agg3"
          ),
          input_id = "rank_list_2"
        ),
        add_rank_list(
          text = "to here",
          labels = NULL,
          input_id = "rank_list_3"
        )
      )
    )
  ),

  fluidRow(
    # giving this the same group name so items from group 1 can be dragged here
    uiOutput("test_drag")
  ),


  fluidRow(
    width = 12,
    bucket_list(
      header = "Group By:",
      group_name = "bucket_list_group_2",
      orientation = "horizontal",
      add_rank_list(
        text = " ",
        labels = list(
          "col1",
          "col2",
          "col3"
        ),
        input_id = "rank_list_4"
      ),
      add_rank_list(
        text = "to here",
        labels = NULL,
        input_id = "rank_list_5"
      )
  )),

  fluidRow(
    column(
      width = 12,
      tags$b("Result"),

          tags$p("input$rank_list_1"),
          verbatimTextOutput("results_1"),

          tags$p("input$rank_list_2"),
          verbatimTextOutput("results_2"),

          tags$p("input$bucket_list_group_1"),
          verbatimTextOutput("results_3"),

          tags$p("input$bucket_list_group_2"),
          verbatimTextOutput("results_4")
    )
  )
)

server <- function(input,output) {

  test_length <- reactive({
    length(input$rank_list_1)
  })

  output$test_drag <- renderUI({

   i <- test_length()

   string <- list()
     for (j in 1:i) {
       string[[j]] <- paste0("add_rank_list(text = \"to here \", labels = NULL,input_id = \"rank_list_", j + 10, "\")")
     }

   test <- paste(as.character(unlist(string)), sep="' '", collapse=", ")

   test <- paste0("bucket_list(header = \" \",group_name = \"bucket_list_group_1\",orientation = \"horizontal\",",test,")")

   eval(parse(text=test))

   })



  output$results_1 <-
    renderPrint(
      input$rank_list_1 # This matches the input_id of the first rank list
    )
  output$results_2 <-
    renderPrint(
      input$rank_list_2 # This matches the input_id of the second rank list
    )
  output$results_3 <-
    renderPrint(
      input$bucket_list_group_1 # Matches the group_name of the bucket list
    )

  output$results_4 <-
    renderPrint(
      input$bucket_list_group_2 # Matches the group_name of the bucket list
    )
}


shinyApp(ui, server)
MayaGans/TableGenerator documentation built on Nov. 11, 2019, 3:14 p.m.