0

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
  })
})

1 Answer 1

1

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.

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)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.