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