闪亮不显示绘图数据

时间:2016-06-25 22:46:04

标签: r ggplot2 shiny

我有一个如下所示的数据集:

   Rk G       Date    Age Team H.A Opponent Outcome Player postMVP game.num variable value
1:  1 1 2004-11-03 30-270  PHO          ATL W (+30) 1      0        1       V1     1
2:  2 2 2004-11-05 30-272  PHO   @      PHI W (+10) 1      0        2       V1     2
3:  3 3 2004-11-06 30-273  PHO   @      NJN W (+32) 2      0        3       V1     3
4:  4 4 2004-11-09 30-276  PHO   @      CHI W (+20) 3      0        4       V1     4
5:  5 5 2004-11-10 30-277  PHO   @      CLE  L (-5) 4      0        5       V1     5
6:  6 6 2004-11-13 30-280  PHO          SAC  L (-2) 2      0        6       V1     6

我使用以下代码创建了一个Shiny应用程序:

服务器:

library(shiny); library(dplyr); library(ggvis); library(mosaic); library(ggplot2); library(data.table)

server <- function(input, output){

plotData <- reactive({ 
var = input$stat
## now filtering on var using the melted data
df <- data %>%
  filter(Player %in% input$Player,
         variable == var)
df
})

 output$plot <- renderPlot({
ggplot(plotData(), aes(x=game.num, y=value, color=Player, shape = postMVP)) + 
  geom_point() + labs(x="Game Number", y = "Value") + scale_fill_discrete(name = "Player, Year")
 })
}

UI:

library(shiny)

shinyUI(fluidPage(

tags$head(
tags$style(HTML("

 .multicol {

   -webkit-column-count: 3; /* Chrome, Safari, Opera */

   -moz-column-count: 3; /* Firefox */

   column-count: 3;

 }

   "))

  ),


 titlePanel(h1('Title', align = "center")),
 hr(),
 mainPanel(
 tabsetPanel(type='tabs',
            tabPanel("Plot", plotOutput("plot")))),
 hr(),
 fluidRow(
   column(2,
       selectInput('stat', "Statistic", choices=c('Field Goal %'='FG.Perc', '3 Pt. %'='ThreePointPerc',"Free Throw %" = "FTPerc", "Rebounds" = "TRB", "Assists" ="ASST", 'Steals' = "STL", "Points" = "PTS", "True Shooting %"= "TrueShootingPerc", "Eff. FG %"= "eFG", "Total Reb. %" = "TRBPerc", "Off. Rating" = "ORtg", "Def. Rating" = "DRtg")))
),

  wellPanel(
  tags$div(class = "multicol", checkboxGroupInput("player", choices = c("one" = 1, "two" = 2, "three" = 3, "four" = 4
    ), label = "Player/Year"
      ))
)

  ))

应用程序运行且没有任何错误,但未显示该图。出现轴和背景,但没有数据图。如果我不过滤数据,即将plotData()更改为总数据集,则数据绘制。因此,我认为在过滤数据时可能会发生一些事情,但我无法弄清楚是什么。

0 个答案:

没有答案