【问题标题】:ERROR: Text to be written must be a length-one character vector, why?错误:要写入的文本必须是长度为 1 的字符向量,为什么?
【发布时间】:2020-03-20 00:02:59
【问题描述】:

我正在尝试在选项卡面板下的 box() 中构建条形图。

这是我的代码:

col1 <- c('upto30', '31-45','46-60','61-75', '76abv')
col2 <- c(10,20,30,40,50)

ui <- shinyUI(dashboardPage(
      dashboardHeader(),
      dashboardSidebar(),
      dashboardBody(
      mainPanel(tabsetPanel(type = 'tab',
      tabPanel("",
      box("",
         barplot(col2)))))          )
))

server <- shinyServer(function(input,output){
})
shinyApp(ui,server)

我不知道为什么在运行应用程序时会出现这样的错误。 谁能帮助解决这个错误“要写入的文本必须是长度为 1 的字符向量”

非常感谢

【问题讨论】:

    标签: r shinydashboard


    【解决方案1】:

    也许您想在server 而不是ui 中呈现您的情节:

    library(shiny)
    library(shinydashboard)
    
    ui <- shinyUI(dashboardPage(
      dashboardHeader(),
      dashboardSidebar(),
      dashboardBody(
        mainPanel(tabsetPanel(type = 'tab'),
                              tabPanel("",
                                       box("",
                                           plotOutput("myPlot")))))                                                     
    ))
    
    server <- function(input,output){
      output$myPlot <- renderPlot(
        barplot(col2)
      )
    }
    
    shinyApp(ui,server)
    

    【讨论】:

    • 感谢 Ben 的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-19
    • 1970-01-01
    • 1970-01-01
    • 2018-03-02
    • 2021-10-12
    • 1970-01-01
    相关资源
    最近更新 更多