5

Trying to create a shiny app where the there is a plot and the selected points create a table with said points.

Having some difficulty locating the source of my error, but have been able to narrow it down to these small section.

library(ggplot2)
library(DT)

ui <- shinyUI(fluidPage(
  fluidRow(uiOutput("plotui")),
  fluidRow(dataTableOutput("plot_brushed_points"))
))

server <- shinyServer(function(input, output){
  output$plot <- renderPlot(plot(mtcars$wt,mtcars$mpg))
  output$plotui <- renderUI(plotOutput("plot",brush = brushOpts("plot_brush")))
  output$plot_brushed_points <- renderDataTable(brushedPoints(mtcars,input$plot_brush,mtcars$wt,mtcars$mpg))
})

myapp <- shinyApp(ui, server)
myapp

The error I receive is the following:

Error in .subset2(x, i, exact = exact) : no such index at level 1

For reference both the plot and table appear as required but when you go to select points the table disappears. Any help would be greatly appreciated.

Andrew Ferris
  • 123
  • 2
  • 11

1 Answers1

2

You should send the variable names instead of the data itself. Try changing:

brushedPoints(mtcars,input$plot_brush,mtcars$wt,mtcars$mpg)

with:

brushedPoints(mtcars,input$plot_brush,"wt","mpg")

Geovany
  • 5,389
  • 21
  • 37