【问题标题】:Render Box Dynamically in Shiny在 Shiny 中动态渲染盒子
【发布时间】:2018-07-17 07:25:44
【问题描述】:

如何根据数据渲染一个闪亮的盒子。 数据由用户上传,它可以有比这更多的数据,所以我必须创建 一个动态的盒子。 我正在运行以下代码,并且在控制台中创建了四个框,而不是在闪亮的网页中。 请看一下,谢谢。

代码

   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) {

  output$nlp_sentences_tree <- renderUI({

    for(i in list_data[[1]]){
     print(box(width = 8,
            i
           )
         )
        }
     }) 
    }

  shinyApp(ui = ui, server = server)

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    看看这里,我已经为每个按钮添加了一个按钮,所以里面有东西

    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)
    

    【讨论】:

    • 我收到了Error in exists: invalid first argument。删除 actionButtons 会删除该错误。或者用actionButton(as.character(i),i) 替换它也可以。
    • 我没有收到错误,我在 shiny 1.1.0shinydashboard 0.7.0
    • 我在shiny 1.0.5 和相同的仪表板版本。
    • @PorkChop 你在 codementor 吗?你能帮忙用闪亮的模块概念制作这个例子吗?
    【解决方案2】:

    或者使用lapplytagList

    server <- function(input, output) {
      output$nlp_sentences_tree <- renderUI({
        a <- lapply(list_data[[1]], function(x) {
          box(width = 8, x)
        })
        tagList(a)
      }) 
    }
    

    【讨论】:

      猜你喜欢
      • 2018-02-24
      • 2020-04-04
      • 1970-01-01
      • 2020-10-09
      • 2015-03-03
      • 2021-07-15
      • 2022-01-25
      • 2018-06-23
      • 2013-11-09
      相关资源
      最近更新 更多