简体   繁体   English

ggplot未显示在闪亮的应用程序中

[英]ggplot not showing up in shiny app

I can't seem to get my plot to come up for this shiny app of the Lahman data. 对于拉曼数据的这款闪亮应用程序,我似乎无法想出办法。 Any help would be greatly appreciated. 任何帮助将不胜感激。

ui.R 用户界面

library(shiny)
library(ggplot2)
shinyUI(fluidPage(
  fluidRow(
sidebarLayout(
  sidebarPanel(
    selectInput("team","Select Team",choices=levels(teamID)),
    sliderInput("year","Include Years in Range",min=1871,max=2014,value=c(1871,2014), sep="")
    ),
  mainPanel(
    plotOutput("pitchingplot")
  )
)
 )
))

server.R 服务器

 library(dplyr)
library(ggplot2)
library(shiny)

shinyServer(function(input, output) {
  Pitching%>%
group_by(input$teamID,yearID)%>%
filter(teamID=input$team,yearID>=input$year[1]& yearID<=input$year[2])
summarise(TotER=sum(ER))

  output$pitchingplot<-renderPlot({
g<-ggplot(data=Pitching,aes(x=yearID,y=TotER)) + geom_point(aes(color=input$team))
g
  })
})

You didn't exactly specify what do you want so it is difficult to help. 您没有完全指定所需的内容,因此很难提供帮助。 All I could do was to make the code working - added reactive dataset data and changed few things. 我所能做的就是使代码正常工作-添加了反应性数据集data并更改了一些内容。

library(shiny)
library(ggplot2)
library(dplyr)
library(Lahman)

data("LahmanData")

ui <- shinyUI(fluidPage(
  fluidRow(
    sidebarLayout(
      sidebarPanel(                                     # added Pithing$
        selectInput("team","Select Team", choices=levels(Pitching$teamID)), 
        sliderInput("year","Include Years in Range",min=1871,max=2014,value=c(1871,2014), sep="")
      ),
      mainPanel(
        plotOutput("pitchingplot")
      )
    )
  )
))



server <- shinyServer(function(input, output) {

  # create a reactive dataset which is passed to ggplot object
  data <- reactive({ 
    Pitching%>%
      group_by(teamID == input$team, yearID)%>% # changed to teamID == input$team
      filter(yearID >= input$year[1] & yearID <= input$year[2]) %>%
      summarise(TotER=sum(ER))
  })

  output$pitchingplot<-renderPlot({
             # changed to data()                 # use aes_string if the variable is passed as a string
    g<-ggplot(data=data(),aes(x=yearID,y=TotER)) + geom_point()
    g
  })
})

shinyApp(ui = ui, server)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM