首页 > 解决方案 > 为什么我的第二个 ggplot 没有出现在我闪亮的应用程序中?

问题描述

使用棒球数据创建闪亮的应用程序。当我运行以下命令时,除了第二个图(折线图)外,一切看起来都很好。我确定我错过了一些小东西,但我无法解决它。

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)

标签: rggplot2shiny

解决方案


您的 plotOutput 宽度在括号之外,即

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

推荐阅读