Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将嵌套列表中的元素传递给renderUI_R_Shiny_Shinydashboard - Fatal编程技术网

将嵌套列表中的元素传递给renderUI

将嵌套列表中的元素传递给renderUI,r,shiny,shinydashboard,R,Shiny,Shinydashboard,我想将每个列表的元素呈现给一个valuebox。 我能够像下面的示例一样显示单个列表的元素(为ex运行代码),但不能显示嵌套列表。 我想要的是valuebox,它由所有列表的元素组成。 请运行代码以了解想法。谢谢 #this should be the result: 1stvaluebox 2ndvaluebox 3rdvaluebox 4thvaluebox A C E H Kim

我想将每个列表的元素呈现给一个valuebox。
我能够像下面的示例一样显示单个列表的元素(为ex运行代码),但不能显示嵌套列表。
我想要的是valuebox,它由所有列表的元素组成。
请运行代码以了解想法。谢谢

#this should be the result:

1stvaluebox    2ndvaluebox  3rdvaluebox   4thvaluebox
A                 C             E             H
Kim               John          Satish        Kevin
1                 2             3             4 


#Data and code

list_data <- list(letters = c("A","C","E","H"),names = c("Kim","John","Satish","Kevin"),numbers = 1:4)

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "Text Mining"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("NLP Tree", tabName = "NLP")
    )
  ),

  dashboardBody(
    tabItems(
      tabItem(tabName = "NLP",
          fluidRow(
            tabBox(width = 12,height="500",
                   tabPanel("Sentences",
                            uiOutput("nlp_entities")
                   )
            ) 
          )  
        )
      )     
    ) 
  )



 server <- function(input, output) {
    output$nlp_entities <- renderUI({
      a <- lapply(list_data[[1]], function(x) {
         valueBox(x,"names")
     })
    tagList(a)
  }) 
 }
   shinyApp(ui = ui, server = server)
#结果应该是:
1 TvValueBox 2 DvValueBox 3 RdValueBox 4 TvValueBox
A C E H
金·约翰·萨蒂什·凯文
1                 2             3             4 
#数据和代码

list_data您可以从1迭代到子列表的长度,每次迭代提取所需信息

server <- function(input, output) {
    output$nlp_entities <- renderUI({
        a <- list()
        for(i in seq_len(lengths(list_data)[1])) {
            a[[i]] <- valueBox(lapply(list_data[c(1, 3)], "[[", i), 
                               list_data[[2]][i])
        }
        tagList(a)
    }) 
}

server谢谢,但这里我希望名称位于“names”位置(即值框的副标题)。谢谢您的回复,我可以知道为什么您添加了那些字符串括号(“[[”@anwar),它是用于
lappy
(工作方式类似于传递提取函数)-我要求从列表中提取i元素。