R 由于输入数据帧错误,条形图未显示

R 由于输入数据帧错误,条形图未显示,r,dataframe,shiny,bar-chart,R,Dataframe,Shiny,Bar Chart,有人能解释一下我试图显示数据的数据框有什么问题吗?引发错误的行被标记为注释 library(dplyr) library(shiny) dlxl<-function(url,sht){ tmp = tempfile(fileext = ".xlsx") download.file(url = url, destfile = tmp, mode="wb") library(readxl) read_excel(tmp,sheet=sht) } csv<-dlxl("ht

有人能解释一下我试图显示数据的数据框有什么问题吗?引发错误的行被标记为注释

library(dplyr)
library(shiny)
dlxl<-function(url,sht){
  tmp = tempfile(fileext = ".xlsx")
  download.file(url = url, destfile = tmp, mode="wb")
  library(readxl)
  read_excel(tmp,sheet=sht)
}
csv<-dlxl("https://www.bls.gov/cps/cpsa2016.xlsx",sht="cpsaat14")
colnames(csv)<-csv[4,]
csv<-csv[6:81,]
colnames(csv)<-make.names(names(as.data.frame(csv)))

ui = bootstrapPage(
  titlePanel("Occupation by Race and Age"),

  sidebarLayout(
    sidebarPanel(
      checkboxGroupInput('age',"Choose Age/Racial Group(s)", choices = unique(as.data.frame(csv)[,1]),selected=NULL),
      checkboxGroupInput('industry',"Choose Industries", choices=colnames(csv),selected=NULL)
    ),
    mainPanel(
      plotOutput("plot1"),
      htmlOutput("text1")
    )
  )
)
server = function(input, output, session){

  output$text1 <- renderUI({HTML(paste("GO"))})

  getData<-reactive({
    shiny::validate(need(length(input$age)>1, "Please select an age"))
    shiny::validate(need(length(input$industry)>1, "Please select an industry"))
    #ages are x axis, y are industry values
    data <-csv[,grepl(input$industry, colnames(csv))]
    data<-cbind(csv[,1],data)
    data2<-data[grepl(input$age, data[,1]),]
    as.data.frame(data2)
})

  output$plot1 <- renderPlot({
    data<-getData()
    shiny::validate(need(nrow(data)>1, "The data for the source you selected was not reported"))
    barplot(data[,2:ncol(data)]) #########ERROR HERE
    #browser()
    #plot(data,names.arg=colnames(data),legend.text = T,beside=T,col =palette()[1:nrow(data)])
  })
}

shinyApp(ui, server)
库(dplyr)
图书馆(闪亮)
dlxl几个错误:

>1
更改为
>0
以检查所选的一个参数(不需要两个)

read\u excel
似乎将所有数字读取为字符串,您必须使用
as.numeric
将它们转换为数字,然后再打印:

barplot(as.numeric(data[,2:ncol(data)]))
barplot(as.numeric(data[,2:ncol(data)]))