dimanche 16 février 2020

Flexdashboard checkboxGroupInput losing ggplot data

I have an issue that is related to [this one][1], but was unable to come to a solution for mine.

I have a reactive ggplot that I would like to update using a check box based on group data.

Currently, when I have ONE box selected, the data displays correctly. If I select more than one check box, I lose data points. See pictures below. I think I have to change the way I'm filtering my data and use droplevels somewhere but not sure how to integrate that (I'm new to shiny!). Any suggestions are appreciated!

checkboxGroupInput("Program", label = "Program", choices = unique(WHOC_Sum_CMJ$Program), selected = "Red", inline = TRUE)

(Note: for the code I cut out some of the styling to make it more readable. That's why it looks different than the pictures).

renderPlot({
  f <- WHOC_Sum_CMJ %>%
  select(Date, Athlete, JumpHeight_cm, Program)%>%
  filter(Program == input$Program)

p <- ggplot(f)+
  geom_line(aes(x=Date, y=JumpHeight_cm, colour = Athlete))+
  geom_point(aes(x=Date, y=JumpHeight_cm, colour = Athlete))+
  theme_bw() +
  labs(title = "Team Jump Height", 
       x = "Date", 
       y = "Jump Height (cm)")+
  scale_x_date(limits = c(min = min(WHOC_Sum_CMJ$Date), max = max(WHOC_Sum_CMJ$Date)), labels = date_format("%m/%d"), 
               date_breaks = "2 weeks", expand = c(.08,0))+
  guides(col = guide_legend(nrow = 3))+
  geom_text_repel(data= subset(f, Date == min(Date)), aes(x=Date, y=JumpHeight_cm,label = unique(Athlete)),
                  force        = .1,
                  nudge_x      = -2,
                  direction    = "y",
                  hjust        = 1,
                  )
p
    })
[![Plot with all items selected][2]][2]
[![What full plot should look like with all items selected][3]][3]


  [1]: https://groups.google.com/forum/#!msg/shiny-discuss/PDPWKRV_lSU/vk8w_qFEJMUJ
  [2]: https://i.stack.imgur.com/FoVXj.png
  [3]: https://i.stack.imgur.com/mNECB.png



Aucun commentaire:

Enregistrer un commentaire