I am learning Shiny from RStudio and I have a matrix of XY co-ordinates in the format ( 0.28414506, 0.42638248 ) with which I am building an IGraph. Using the brush method I can get the range of XY min max co-ordinates. I want to take the range of co-ordinates and find the index values of points taken in by the brush method. The shiny tutorials for near points work off dataframes but my initial data is a matrix.
My question is similar to Is there an R function for finding the index of an element in a vector? but my elements won't be exact matches, they will be a range. Here's my code so far, any help would be appreciated.
ui <- basicPage(
plotOutput("plot1",
click = "plot_click",
dblclick = "plot_dblclick",
hover = "plot_hover",
brush = "plot_brush"),
verbatimTextOutput("info")
)
server <- function(input, output) {
output$plot1 <- renderPlot({
plot(g, layout=layout1, rescale=FALSE, axes=TRUE, xlim = range(layout1[,1]), ylim = range(layout1[,2]))
})
output$info <- renderText({
xy_str <- function(e) {
if(is.null(e)) return("NULL\n")
paste0("x=", round(e$x, 8), " y=", round(e$y, 8), "\n")
}
xy_range_str <- function(e) {
if(is.null(e)) return("NULL\n")
paste0("xmin=", round(e$xmin, 8), " xmax=", round(e$xmax, 8),
" ymin=", round(e$ymin, 8), " ymax=", round(e$ymax, 8))
}
paste0(
"click: " , xy_str(input$plot_click),
"dblclick: ", xy_str(input$plot_dblclick),
"hover: " , xy_str(input$plot_hover),
"brush: " , xy_range_str(input$plot_brush)
)
})
}
shinyApp(ui, server)