将输入返回为反应式闪亮列表中的列表-插入UI中的动态UI

问题描述

我正在使用先前解决方案R shiny dynamic UI in insertUI中的代码

现在在我的应用中,输入由服务器呈现,并显示为不同的元素/行,如下所示

$row_1
[1] "LV1" "x1" "x2" "x3"

$row_2
[1] "LV2" "x4" "x5" "x6"

我实际上是希望得到这样的东西:

"LV1" "x1" "x2" "x3"
"LV2" "x4" "x5" "x6"

我尝试了一些操作,但是不确定如何更改handle()函数以获取所需的输出。

屏幕截图和代码:

如果尝试运行闪亮的应用程序,则会看到以下内容:

enter image description here

点击+ LV按钮,然后只需选择LV1,然后多选x1 x2 x3,依此类推。

输出结果如下:

enter image description here

这是完整的代码

library(shiny)

newlist <- as.list(c("LV1","LV2","x1","x2","x3","x4","x5","x6"))

row_ui <- function(id) {
  ns <- NS(id)
  fluidRow(
 
     column(2,uiOutput(ns("ui_placeholder"))),column(2,uiOutput(ns("ui_placeholder2"))
    )
  )
} 

row_server <- function(input,output,session) {
  
  
  return_value <- reactive({c(input$variable1,input$variable2)})
  ns <- session$ns
  output$ui_placeholder <- renderUI({
 
      selectInput(ns("variable1"),"LV:",choices = c(' ',newlist),selected = NULL)
      
  })
  
  output$ui_placeholder2 <- renderUI({
    selectInput(ns("variable2"),"Ind:",selected = NULL,multiple = TRUE)
  })
  
   list(return_value = return_value) 
}

ui <- fluidPage(  
  div(id="placeholder"),actionButton("addLine","+ LV"),verbatimTextOutput("out"),verbatimTextOutput("listout5")
)



server <- function(input,session) {
  
  handler <- reactiveVal(list())
  observeEvent(input$addLine,{
    new_id <- paste("row",input$addLine,sep = "_")
    insertUI(
      selector = "#placeholder",where = "beforeBegin",ui = row_ui(new_id)
    )
    handler_list <- isolate(handler())
    new_handler <- callModule(row_server,new_id)
    handler_list <- c(handler_list,new_handler)
    names(handler_list)[length(handler_list)] <- new_id
    handler(handler_list)
  })
  
  output$out <- renderPrint({
    lapply(handler(),function(handle) {
      handle()
    })
  })
  
 
}

shinyApp(ui,server)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)