I have a data frame which look like that :
Taux_retour = as.Date(c("2020-06-11", "2020-06-12", "2020-06-13", "2020-06-15",
"2020-06-16", "2020-06-17", "2020-06-18", "2020-06-19",
"2020-06-20", "2020-06-22", "2020-06-23", "2020-06-24", "2020-06-25"))
Taux_retour=as.data.frame(Taux_retour)
Taux_retour$n = c(183,94,3,233,247,200,181,125,3,144,155,146,116)
Taux_retour$`Retour (%)`= c(1.55,0.79, 0.03, 1.97, 2.09, 1.69, 1.53, 1.06, 0.03, 1.22, 1.31, 1.23, 0.98)
In my shiny web app, I'd like to make a plot and to print the data.frame used to create it juste under the graph. When my computer mouse is on a point, I'd like the related informations to appears. for exemple if I point the first one, want R to print the first line f the data.frame.
Here is the code :
ui = dashboardPage(
fluidRow(
box(title = "Evolution du taux de retour :
(pour plus de détails, passez votre souris sur les points)",
status = "success",
width = 9,
solidHeader = TRUE,
plotOutput('graphique',
click = "image_click",
hover = hoverOpts(id = "plot_hover", delayType = "throttle")),
uiOutput("dynamic"))))
server = function(input, output) {
output$graphique= renderPlot({
ggplot(data=Taux_retour, aes(x=Taux_retour,y=`Retour (%)`))+geom_line(col="steelblue", lwd=1) +
ylim(min(Taux_retour$`Retour (%)`), max(Taux_retour$`Retour (%)`)) + theme_light() + theme(legend.position='none') +
labs(y = "Taux de retour (en %)", x="Dates") +
geom_line() + geom_point()+
geom_vline(xintercept=as.numeric(as.Date(env1)+1), color = "olivedrab") +
annotate(geom="text",x=as.Date(env1_g),y=2.0,label="Premier envoi", fontface="bold", color = "#006600")
})
output$dynamic <- renderUI({
hover <- input$plot_hover
y <- nearPoints(iris, input$plot_hover) # HERE
req(nrow(y) != 0)
verbatimTextOutput("vals")
})
output$vals <- renderPrint({
hover <- input$plot_hover
y <- nearPoints(iris, input$plot_hover) # HERE
req(nrow(y) != 0)
y
})
}
shinyApp(ui = ui, server = server)
The problem is that nothing happens when I'm mooving my mouse over the graph. I think I have to select some lines where it's written "# HERE" in the code but I can't get what ! If you have any ideas it would be great, I spend like 8 hours on that error ..
I'm also sorry for the errors in my language... You must have understood i'm not a nativ speacker..