如何在R Shiny中创建雷达图

时间:2019-06-04 17:20:50

标签: r shiny shinydashboard

我一直试图在R Shiny中创建一个交互式雷达图或蜘蛛图。 根据下面的代码,我遇到了一个错误:“找不到对象df1”。 仍然不确定如何创建雷达图。

我希望能用几年来操纵蜘蛛图,并以雷达图中的顶点作为度量。

我的数据框如下所示,我是否需要转置?

player.currentTime(time)

Server.r

STATE   YEAR    measure    value

CA      2017    all_am     5000
NY      2017    all_am     6000  
FL      2017    all_am     7000
CA      2017    all_hw     5000
NY      2017    all_hw     6000  
FL      2017    all_hw     7000

CA      2016    all_am     5000
NY      2016    all_am     6000  
FL      2016    all_am     7000
CA      2016    all_hw     5000
NY      2016    all_hw     6000  
FL      2016    all_hw     7000

CA      2015    all_am     5000
NY      2015    all_am     6000  
FL      2015    all_am     7000
CA      2015    all_hw     5000
NY      2015    all_hw     6000  
FL      2015    all_hw     7000

ui.r

install.packages("shinydashboard")

library(shiny)
library(ggplot2)
library(dplyr)
library(leaflet)
library(shinydashboard)
library(graphics)
require(radarchart)


shinyServer(function(input, output) {

  df <- read.csv("C:/Users/Shruti/Desktop/Try2/newT1.csv")
  head(df)  

  df1 <- df[, (names(df) %in% c("STATE", "YEAR", "measure", "value"))]
  head(df1)


  df1[is.na(df1)] <- 0


  yearinput <- reactive({
    df1%>%
      filter(value == input$years)})   

  output$radarPlot <- renderchartJSRadar({


races <- df1[which(yearinput()$measure)]

chartJSRadar(races, distinct(raceinput()$measure))           

  })
})

0 个答案:

没有答案