title: Get row number from of data point from event_data
body: <p>I have been creating a data viewer app using shiny and plotly. I want to make a create a multi dimensional scaling view of my data, and then click on a data point to be able to view the individual point as a barplot. I was inspired by <a href="https://plot.ly/r/shiny-coupled-hover-events/" rel="nofollow">this</a> example.</p>
  
  <p>Here is a minimal almost working example:</p>
  
  <h1>The ui.r file</h1>
  
  <pre><code>library(shiny)
  library(mlbench)
  library(plotly)
  library(shinythemes)
  library(dplyr)
  
  # Load the data
  allDat &lt;- iris[,-5]
  
  # ui.R definition
  ui &lt;- fluidPage(
    # Set theme
    theme = shinytheme("spacelab"),
  
    # Some help text
    h2("Inspect each element in iris data set"),
    h4("This a shiny app exploiting coupled events in plotly"),
    tags$ol(
      tags$li("The first chart showcases", tags$code("plotly_click"))
    ),
  
    # Vertical space
    tags$hr(),
  
    # First row
    fixedRow(
      column(6, plotlyOutput("Plot1", height = "600px")),
      column(6, plotlyOutput("Plot2", height = "600px"))),
  
    tags$hr())
  </code></pre>
  
  <h1>The server.r file</h1>
  
  <pre><code># server.R definition
  server &lt;- function(input, output){
  
    d &lt;- dist(allDat) # euclidean distances between the rows
    fit &lt;- cmdscale(d,eig=TRUE, k=2) # k is the number of dim
  
    # plot solution
    x &lt;- fit$points[,1]
    y &lt;- fit$points[,2]
    plot.df &lt;- data.frame(x=x,y=y,allDat)
  
    output$Plot1 &lt;- renderPlotly({
      plot_ly(plot.df, x = x, y = y, mode="markers", source = "mds") %&gt;%
        layout(title = "MDS of iris data",
               plot_bgcolor = "6A446F")
    })
  
    # Coupled event 2
    output$Plot2 &lt;- renderPlotly({
  
      # Try to get the mouse click data
      event.data &lt;- event_data("plotly_click", source = "mds")
  
      # If NULL dont do anything
      if(is.null(event.data) == T) return(NULL)
  
      # I need the row of the data in the allDat data frame
      # pretty sure this is not correct
      ind &lt;- as.numeric(event.data[2])
  
      p1 &lt;- plot_ly(x = colnames(allDat), y=as.numeric(allDat[ind,]),type="bar")
  
    })
  
  }
  </code></pre>
  
  <p>To run this, put these two files in a folder called something, e.g. dataViewer, then run <code>runApp("dataViewer")</code> from the directory that contains the dataViewer folder.</p>
  
  <h1>What is the question and what am I seeking?</h1>
  
  <p>I do not understand the output that comes from the <code>event_data</code> function. I want to be able to click on a point on the scatter plot and extract the row number of that data point from the <code>allDat</code> data frame, or the <code>plot.df</code> data frame, because it should be the same. Then I want to use that row number to further visualize that specific point in the barplot on the right.</p>