如何使用gvisBarChart显示y的计数或y的平均值

时间:2015-07-22 09:24:16

标签: r rstudio

我有如下代码,并尝试使用从下拉列表中选择的数据绘制gvisBarChart。 Server.r和ui.r代码在下面给出

#server.r

shinyServer(function(input, output, session) {

 output$ShowdataColDropDown <- renderUI({
   df <-filedata()
   if (is.null(df)) return(NULL)
   #Let's only show numeric columns
   nums <- sapply(df, is.numeric)
   numitems=names(nums[nums])
   selectizeInput("VarData", "Select Data:",c("", numitems()),  multiple=TRUE, options = list(maxItems = 2,placeholder = 'select x and y  parameters'))
   })

  output$ShowdataCatDropDown <- renderUI({
    df <-filedata()
    #Let's only show numeric columns
    nums <- sapply(df, is.numeric)
    numitems=names(nums[nums])
    names(numitems)=numitems
    selectInput("charData", "Select Data:",c("", numitems), selected=numitems[1]) 
    })

output$myplot<-renderGvis({
   #data
   filedata <- data.frame(product=c("A","A","A","B","B"),Sales= c(10,3,4,2,20))

   dfall<-data.frame(cbind(filedata[input$VarData],filedata[input$charData]))

  #input$VarData is the input selected by the user for say 'sales'
  #input$charDatais the input selected by the user for say 'product'


  #The barchart code below is not working; Getting the error as: arguments must      have same length
   gvisBarChart(aggregate(dfall, list(dfall[input$charData]),mean))

    })
  }

#UI.r

 shinyUI(
   fluidPage(
   uiOutput("ShowdataColDropDown"),
   uiOutput("ShowdataCatDropDown"),
   htmloutput("myplot")
  )

请帮我按产品的平均值(销售额)显示图表。

0 个答案:

没有答案