I have a shiny app posted here https://statspot.shinyapps.io/shiny_test/
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?
filled.contour(x=seq(100,1200,100),y=log10(c(1E15,1E16,1E17,1E18,1E19,1E20)),
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"),
verbatimTextOutput("info")
my recommendation is to switch from using the filled.contour plotting function in favour of ggplot2.
example:
library(shiny)
library(ggplot2)
#example contour data
df <- expand.grid(x=-50:50,
y=0:100)
df$z <- df$x + abs(df$x*df$y) -sin(df$y)*100
ui <- fluidPage(
plotOutput(outputId = "distPlot",click = "plot_click"),
verbatimTextOutput("info")
)
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)
system
Closed
February 23, 2021, 7:43pm
3
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.