Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
203 views
in Technique[技术] by (71.8m points)

r - Why is my second ggplot not appearing in my shiny app?

Creating a shiny app with baseball data. When I run the following, everything appears fine except the second plot (line graph). I'm sure I'm missing something small but I haven't been able to solve it.

ui <- fluidPage(
  selectInput(inputId = "num1",
              label = "Select Pitcher",
              choices = levels(PitcherName),
              selected = NULL
  ),
  fluidRow(plotOutput("PitchLoc"), width = 5,
           plotOutput("PitchVol"), width = 5)
  
)
server <- function(input, output) {
  output$PitchLoc <-renderPlot({
    bp <- GameData %>% filter(PitcherName == input$num1, 
    )
    ggplot(bp, aes(x=PlateLocSide, y=PlateLocHeight)) +
      geom_point(aes(color = TaggedPitchType)) +
      scale_color_manual(values = c('black','blue','red','purple','yellow')) +
      geom_path(data = sz, aes(x=x, y=z)) +
      xlim(-3,3) +
      ylim(0,6) +
      ggtitle("Pitch Location by Pitch Type")
    
  })
  
  output$PitchVol <-renderPlot({
    vol <- GameData %>% filter(PitchSelect %in% c("Fastball", "Curveball", "Slider", "ChangeUp"),
                               Pitcher == input$num1        
    ) %>%
      ggplot(aes(x=PitchNo, y=RelSpeed,)) +
      geom_line(aes(group=TaggedPitchType, color=TaggedPitchType)) +
    ggtitle("Pitch Velocity")
  })
}

shinyApp(ui = ui, server = server)
question from:https://stackoverflow.com/questions/66056496/why-is-my-second-ggplot-not-appearing-in-my-shiny-app

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your plotOutput width is outside the parentheses, i.e.

fluidRow(plotOutput("PitchLoc", width = 5),
           plotOutput("PitchVol", width = 5))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...