Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create N x M (lists vs items) and restoring the session #101

Open
Andryas opened this issue Jun 3, 2023 · 0 comments
Open

Create N x M (lists vs items) and restoring the session #101

Andryas opened this issue Jun 3, 2023 · 0 comments

Comments

@Andryas
Copy link

Andryas commented Jun 3, 2023

I have a problem connecting N destinations with M origins, and both are dynamically created in my shiny app. After completion, the user must drag from the first list to one of N destinations, and then the results are stored. Also, when the app is initialized, I should be able to restore the way it was.

Below is an example of how I am creating this N x M, but I need help restoring the way it was.

Is it in the roadmap that allows adding many lists dynamically and also updating those rank lists?

Thank you very much

library(shiny)
library(sortable)

ui <- fluidPage(
  fluidRow(
    style = "display: flex; flex-direction: row; justify-content: space-around; margin: 27px;",
    numericInput("generate_n", "Generate N lists", 2),
    numericInput("generate_m", "Generate M items", 3)
  ),
  uiOutput("dragAndDropList")
)

server <- function(input, output) {

  output$dragAndDropList <- shiny::renderUI({
    req(input$generate_n, input$generate_m)

    list_n <- 1:input$generate_n
    list_m <- 1:input$generate_m

    p <- paste0('sortable::bucket_list(
        header = "Dynamic bucket list",
        group_name = "dynamic_group",
        orientation = "horizontal",
        sortable::add_rank_list(
          text = "Items to distribute",
          labels = as.character(list_n),
          input_id = "items"
        ),
        ${dynamic_rank}
      )')

    ll <- purrr::map(list_m, function(.x) {
      paste0('sortable::add_rank_list(text = "', .x, '", labels = NULL, input_id = paste0("list", ', .x, "))")
    })
    dynamic_rank <- paste0(ll, collapse = ",")

    eval(parse(text = stringr::str_interp(p)))
  })
}


shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant