r - 在Shiny中,读取excel文件并将其绘制在GGPLOT中

时间:2018-01-30 14:38:59

标签: r ggplot2 shiny

我是Shiny的新手,我正在开发一个项目,它将加载Excel数据并将其绘制在GGPLOT中。我一直在Stackoverflow上查看过去的问题/答案,我不知道问题是什么。我需要反应吗?我粘贴在已经完成的东西之下。我将要上传的Excel数据将始终采用相同的格式(相同的标题),但只是不同的数据(即我希望始终查看相同的三个标题:" number"," update_date"和" media-type)。

###UI
library(shiny)
library(readxl)
library(ggplot2)

shinyUI(fluidPage(
  titlePanel("Visualizing Data"),
  sidebarLayout(
    sidebarPanel(
      fileInput('file1', 'Choose xlsx file',
                accept = c(".xlsx")
      )
    ),
    mainPanel(
      plotOutput('plot1'))
  )
))

###Server
library(shiny)
library(readxl)
library(ggplot2)

shinyServer(function(input, output) {
  output$plot1 <- renderPlot({
    inFile <- input$file1
    if(is.null(inFile))
      return(NULL)
    df<-read_excel(inFile$datapath)
    ggplot(data=df,aes(x=`Update date`,y=number,colour=`Media 
Type`))+geom_line(stat="identity")+ggtitle("Comparison")
  })
}
)

0 个答案:

没有答案