Rshiny--使用CSV文件创建条形图 [英] Rshiny--creation of bar plot using CSV file

查看:0
本文介绍了Rshiny--使用CSV文件创建条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案

您可以先读取文件,然后使用条形图进行渲染,如下所示:

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)
工作演示截图:

这篇关于Rshiny--使用CSV文件创建条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆