I have a question about using a reactive DF in the nearPoints function. I can't seem to find any info about it and can't get it to work. (I'm relatively new to shiny and have beginner-to-moderate experience in R.)
I have a reactive that spits out a DF used for a ggplot2 (point & line plot). I am then trying to use nearPoints to get the rows of DF that a user selects (mouse click) but nothing is being returned. (Eventually, I want to use that data to produce another plot.)
UI:
in a tabsetPanel
...some_UI_stuff...
plotOutput( "the_plot", height = 500, click = "plot_click" ),
verbatimTextOutput("click_info")
It produces a row of column titles correctly but always shows:
"<0 rows> (or 0-length row.names)"
when I click on a point in the plot (unless allRows = TRUE
is used in the server (see below)).
server:
DF <- reactive({ makes_some_magic_ happen & return(df) })
output$the_plot <- renderPlot({ validate( some-things )
ggplot( DF(), aes(blahblah) ) +
geom_point() +
geom_line() +
some_scale/label/theme/facet_options
})
output$click_info <- renderPrint({ str(input$plot_click) })
produces the expected output (the input$plot_click
list), but
output$click_info <- renderPrint({ nearPoints(DF(), input$plot_click) })
gives <0 rows> ...
and
output$click_info <- renderPrint({ nearPoints(DF(), input$plot_click, allRows = TRUE) })
shows the selected_ column
as always FALSE
no matter which point I click.
Thanks in advance.