【问题标题】:Rshiny--creation of bar plot using CSV fileR Shiny——使用 CSV 文件创建条形图
【发布时间】:2019-02-01 15:21:29
【问题描述】:

我希望将条形图嵌入到应用程序中。向量 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)

【问题讨论】:

  • 我已经为您添加了解决方案。如果有更多信息,请您检查并告诉我!

标签: r shiny shinydashboard


【解决方案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)

工作演示的屏幕截图:

【讨论】:

  • 是否可以使用另一个字段使其交互,并且这个条形图应该改变.....
  • @nitisethi:是的,这是可能的。如果它对您有用,请考虑将此答案标记为已接受。谢谢
  • 我更愿意提出详细信息的新问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-01-10
  • 2022-11-29
  • 1970-01-01
  • 2016-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多