Rshiny-使用CSV文件创建条形图

时间:2019-02-01 07:08:55

标签: r shiny shinydashboard

我希望将条形图嵌入到应用程序中。向量d的输出给我结果,我希望将其嵌入到Shinyapp中,以后我也希望使其具有交互性。

 library(ggplot2)

 driver1 <- read.csv("E:/RMARKDOWN/shiny/driver.csv",header = T)

 New_DataSet1<- 
 data.frame(driver1$ï..Year_AG,driver1$Severity_Desc,driver1$Injury.Type)
  New_DataSet1

  latest <- New_DataSet1[1:100,]
  latest

  d <- aggregate(latest$driver1.Injury.Type,  by=list(chkID = 
       latest$driver1.Severity_Desc), FUN=sum)


 ui <- dashboardPage(
  dashboardHeader(title = "Row layout"),
   dashboardSidebar(),
    dashboardBody()
      )


  server <- function(input, output) { 

   #output$plot <- renderPlot({    barplot(d$x, xlab = d$chkID)  })

  renderPlot(d$x)
  #barplot(d$x, xlab = d$chkID)
 # barplot(d$x, names.arg = d$chkID)

  }

      shinyApp(ui,server)

1 个答案:

答案 0 :(得分:1)

您可以先阅读文件,然后使用如下条形图进行呈现:

library(plotly)
library(shiny)


ui <- fluidPage(
  mainPanel(
    plotlyOutput("chart")
  )
)

server <- function(input, output, session) {
  output$chart <- renderPlotly({
    # write code here to read data from csv file
    df=read.csv("")

    # Set x and y axis and display data in bar chart using plotly
    p <- plot_ly( x = iris$Species,
                  y = iris$Sepal.Length,
                  name = "Iris data",
                  type = "bar") 
  })
}

shinyApp(ui, server)

工作演示中的屏幕截图: enter image description here