Rshiny--creation of bar plot using CSV file

半城伤御伤魂 提交于 2019-12-25 01:48:13

问题


I want the bar plot to be embedded into application.output of vector d is giving me result I want that to be embedded into shinyapp and later I want to make it interactive too.

 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:


You can read file first and render it using bar chart as below:

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)

Screenshot from working demo:



来源:https://stackoverflow.com/questions/54474561/rshiny-creation-of-bar-plot-using-csv-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!