0

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)
Community
  • 1
  • 1
Harunhh123
  • 53
  • 7
  • 1
    When i try to run this i get an error that `layout1` is not defined. Please make sure your example is [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick Apr 29 '16 at 02:37
  • Apologies for that, there's a lot of code before the shiny app that gets the layout1 variable. I completely understand that it would be annoying. Mostly the coode beforehand is based on this RBloggers article which uses the layout1 variable. http://www.r-bloggers.com/an-example-of-social-network-analysis-with-r-using-package-igraph/ – Harunhh123 Apr 29 '16 at 03:08

0 Answers0