Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Shiny - No Such Index At Level 1

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.

like image 389
Andrew Ferris Avatar asked Nov 01 '22 00:11

Andrew Ferris


1 Answers

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")

like image 178
Geovany Avatar answered Nov 15 '22 07:11

Geovany