Plot x coordinate returned is wrong when using click in plotOutput

I have a shiny app posted here

I use a filled contour plot and try to get the x,y values using the "click" parameter. If you try to click the x it returns is always about 50 units off from where you click on the graph. Any idea what I might be doing wrong?

                   z=data_matrix_mod,xlab="T",ylab="log N",
                   color.palette = function(n) hcl.colors(n, input$color_scheme))

  output$info <- renderText({
    paste0("T=", input$plot_click$x, "\n N=", input$plot_click$y)

In ui

      plotOutput(outputId = "distPlot",click = "plot_click"),

my recommendation is to switch from using the filled.contour plotting function in favour of ggplot2.


#example contour data 

df <- expand.grid(x=-50:50,
df$z <- df$x + abs(df$x*df$y) -sin(df$y)*100

ui <- fluidPage(
  plotOutput(outputId = "distPlot",click = "plot_click"),

server <- function(input, output, session) {
  output$distPlot <- renderPlot(
      ggplot(data=df) + 
        aes(x = x, y = y, z = z, fill = z) + 
        geom_tile() + 
        coord_equal() +
        geom_contour(color = "white", alpha =.5) + 
        scale_fill_distiller(palette="Spectral", na.value="white")
  output$info <- renderText({
    paste0("x=", input$plot_click$x, "\n y=", input$plot_click$y)

shinyApp(ui, server)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.