错误:要写入的文本必须是一个长度为1的字符向量,为什么?

问题描述 投票:0回答:1

我正在尝试在Tabpanel下的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)

我不知道为什么在运行应用程序时会出现这样的错误。任何人都可以帮助解决此错误“要写入的文本必须是长度为一的字符向量”

非常感谢

r shinydashboard
1个回答
0
投票

也许您想在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)
© www.soinside.com 2019 - 2024. All rights reserved.