brushedPoints how can i use the resulting data.frame in the server

27 views
Skip to first unread message

lloyd....@gmail.com

unread,
Oct 23, 2016, 9:30:47 AM10/23/16
to Shiny - Web Framework for R

ui <- basicPage(

  plotOutput("plot1", click="plot_click", brush = "plot_brush", ),

  verbatimTextOutput("info")

)


server <- function(input, output) {

  output$plot1 <- renderPlot({

    plot(mtcars$wt, mtcars$mpg)

  })


#  this works !


#  output$info <- renderPrint({

    # With base graphics, need to tell it what the x and y variables are.

#    brushedPoints(mtcars, input$plot_brush, xvar = "wt", yvar = "mpg")

#  })


#   This DOES NOT WORK !

brushed.rows.expr <- eventReactive( input$plot_brush, {

    brushedPoints(df=mtcars, input$plot_brush, xvar='wt', yvar='mpg' )

  })


brushed.rows.df=isolate( brushed.rows.expr() )  # subset of the data df

#  >boom<   with a brief error msg: 'error:'


if( dim(brushed.rows.df)[1] > 1 )

     write.table( x=brushed.rows.df, file=' brushed.rows.csv', append = FALSE, quote = FALSE, sep = ", ", eol = "\n", na = "NA", dec = ".",  row.names = T,

col.names = TRUE, qmethod = c("escape", "double"),

fileEncoding = "")


}


shinyApp(ui, server)


Thank you in advance. I have been playing with this for days. I don't seem to understand reactivity.

Lloyd


lloyd....@gmail.com

unread,
Oct 23, 2016, 1:04:47 PM10/23/16
to Shiny - Web Framework for R

after some experimentation and research, i came up with this:

ui <- fluidPage(


plotOutput("plot1", click="plot_click", brush = "plot_brush", ),

verbatimTextOutput("info" )

)


server <- function(input, output) {

output$plot1 <- renderPlot({

plot(mtcars$wt, mtcars$mpg)

})


df = eventReactive( input$plot_brush, {

brushedPoints(mtcars, input$plot_brush, xvar = "wt", yvar = "mpg")

} )


observe(

{ dd=df();

names(dd);

print(dd); } )


}


shinyApp(ui, server)



 

 

 
Reply all
Reply to author
Forward
0 new messages