Render Box Dynamically in Shiny

北城以北 提交于 2019-12-06 16:06:07

Have a look here, I've added a button to each just so something is in there

library(shinydashboard)
library(shiny)

list_data <- list(c("AB","CD","EF","GH"))  #data

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_sentences_tree")
                       )
                ) 
              )  
      )
    )   
  )
)



server <- function(input, output) {

  v <- list()
  for (i in 1:length(list_data[[1]])){
    v[[i]] <- box(width = 8, list_data[[1]][i],actionButton(i,i))
  }
  output$nlp_sentences_tree <- renderUI(v)
}

shinyApp(ui = ui, server = server)

Or with an lapply and tagList:

server <- function(input, output) {
  output$nlp_sentences_tree <- renderUI({
    a <- lapply(list_data[[1]], function(x) {
      box(width = 8, x)
    })
    tagList(a)
  }) 
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!