列表列表未创建列表列表

时间:2018-07-10 19:06:51

标签: shiny

我正在尝试生成列表列表-<-append(a,list(b)),而不只是元素列表。我遇到的问题是,我得到的不是列表列表,而是列表列表。请在下面查看程序和输出

CODE

library(shiny)
library(shinyjs)
firstUI <- function(id) { uiOutput(NS(id, "first")) }

firstServer <- function(input, output, session){#, a) {
  ns = session$ns
  # returnedValue = NULL
  output$first <- renderUI({

    # selectInput(ns("select"), h4("Select"), paste0(isolate(a()), letters[1:4]))
    selectInput(ns("select"), h5(strong("Please select from the list")), choices = c("", "a", "b", "c", "d"), multiple=TRUE, selectize=TRUE)

  })
  # res <- reactive({
  #  if (length(input$select) > 1) {
  #   paste0(input$select)
  #} else {
  # ""
  #  }
  #  })
  returnedValue <- reactive({paste0(input$select)})
  return(returnedValue)
}


removeFirstUI <- function(id) {
  removeUI(selector = paste0('#', NS(id, "first")))
}

addRmBtnUI <- function(id) {
  ns <- NS(id)
  tags$div(
    actionButton(inputId = ns('insertParamBtn'), label = "Add"),
    actionButton(ns('removeParamBtn'), label = "Remove"),
    hr(),
    tags$div(id = ns('placeholder'))
  )
}

addRmBtnServer <- function(input, output, session, moduleToReplicate, ...) {
  ns = session$ns
  params <- reactiveValues(btn = 0, inputFiles = list())
  observeEvent(input$insertParamBtn, {
    params$btn <- params$btn + 1
    params$inputFiles[[params$btn]] <- callModule(moduleToReplicate$server, id = params$btn, ...)
    insertUI(
      selector = paste0('#', ns('placeholder')),
      ui = moduleToReplicate$ui(ns(params$btn))
    )
  })

  observeEvent(input$removeParamBtn, {
    moduleToReplicate$remover(ns(params$btn))
    params$btn <- params$btn - 1
  })

  return(params)
}
ui <- fluidPage(
  addRmBtnUI("addRm"),
verbatimTextOutput("text", placeholder = TRUE),
actionButton("saveBTN", "Press the save button to end"),
verbatimTextOutput("list"),
verbatimTextOutput("listOfLists")

)
server <- function(input, output, session){

  comp <- callModule(
    addRmBtnServer, id = "addRm",
    moduleToReplicate = list(
      ui = firstUI,
      server = firstServer,
      remover = removeFirstUI
    )
  )

  myValues <- reactiveValues()
  observe({
    if(comp$btn>0 && length(comp$inputFiles[[comp$btn]]())  > 1){
      myValues$fList <- c(isolate(myValues$fList), isolate(list(comp$inputFiles[[comp$btn]]())))
    }
  })

 output$listOfLists<-renderPrint({
     result <- receivelist(myValues$fList)
    shinyjs::show("saveBTN")
    paste(result$x, result$L)
   })


   receivelist <- function(myList){
    x <- list()
     #x <- extend(x, myList)
     x <- append(x, myList)
     L <- length(x)
     # print(paste(x, length(x)))
     list(x = x, L = L)

   }
}

shinyApp(ui = ui, server = server)
```

I was not able to paste the GUI so I am just pasting the text that appears in the GUI.  As you can see every time a list is added to the previous list, the previous list is repeated before the new added list is displayed.  What I would like to get is the 3 results below;
"c(\"a\", \"b\") 3"               "c(\"a\", \"b\", \"c\") 3"      "c(\"a\", \"b\", \"c\", \"d\") 3"

In this block of code code, i defined the myValues$List - list(comp$inputFiles[[comp$btn]]())) as a list because otherwise, I just get a list of elements.  Could you please help me with this?

Thank you
```
  myValues <- reactiveValues()
  observe({
    if(comp$btn>0 && length(comp$inputFiles[[comp$btn]]())  > 1){
      myValues$fList <- c(isolate(myValues$fList), isolate(list(comp$inputFiles[[comp$btn]]())))
    }
  })

这是我得到的输出。如何避免重复?

输出

请从列表中选择 一种 b 请从列表中选择 一种 b C 请从列表中选择 一种 b C d

[1]“ c(\” a \“,\” b \“)6”“ c(\” a \“,\” b \“)6”“ c(\” a \“,\ “ b \”,\“ c \”)6“” c(\“ a \”,\“ b \”)6“
[5]“ c(\” a \“,\” b \“,\” c \“)6”“ c(\” a \“,\” b \“,\” c \“,\” d \“)6”

0 个答案:

没有答案