Adding a download button to save selected brush points in shiny

How would I add a download button/ option to save selected brush points on shiny? where would I add it into this code:

server <- function(input,output, session) {
#library(svDialogs)
library(ggplot2)

output$plot <- renderPlot({
  ggplot(depths, aes(time2, value, color=Type.of.Data)) + geom_point()+
    labs(y='Value', size=22)  +
    theme(text = element_text(size=16))
})

dat <- reactive({
  user_brush <- input$user_brush
  brushedPoints(depths, user_brush, xvar = "time2", yvar = "value")
})
output$table <- renderTable({
  dat()
  
})
output$dep <- renderText({
  
  means <- aggregate(value ~ Type.of.Data, FUN=mean, data=dat())
  paste0("Mean depth (m) = ", round(means$value[1],1))
  
})

output$wattemp <- renderText({
  
  means <- aggregate(value ~ Type.of.Data, FUN=mean, data=dat())
  paste0("Mean temperature = ", round(means$value[3],3))
  
})

output$spread <- renderText({
  
  means <- aggregate(value ~ Type.of.Data, FUN=mean, data=dat())
  paste0("Mean Spread = ", round(means$value[2],2))
  
})

output$starttime <- renderText({
  
  start.time <- min(dat()$time2)
  stime<-as.POSIXct(start.time, origin='1970-01-01')
  paste0("Start time = ", stime)
  
})

output$endtime <- renderText({
  end.time <- max(dat()$time2)
  etime<-as.POSIXct(end.time, origin='1970-01-01')
  paste0("End time = ", etime)
  
})

output$elapstime <- renderText({
  start.time <- min(dat()$time2)
  stime<-as.POSIXct(start.time, origin='1970-01-01')
  end.time <- max(dat()$time2)
  etime<-as.POSIXct(end.time, origin='1970-01-01')
  eltime <- etime - stime
  paste0("Elapsed time (minutes) = ", round(eltime,2))
  
})

}

#############################

This is the ui section that lets you interact with and run the code in the server section.

ui <- fluidPage(

h3("Click and hold/drag to select the data you want to use for calculation of mean fishing depth and temperature"),
plotOutput("plot", brush = "user_brush"),
tableOutput("dat"),
textOutput("dep"),
textOutput("wattemp"),
textOutput("spread"),
textOutput("starttime"),
textOutput("endtime"),
textOutput("elapstime"),
tags$style("#wattemp {font-size:20px;
         color:black;
         display:block; }"),
tags$style("#spread {font-size:20px;
         color:black;
         display:block; }"),
tags$style("#dep {font-size:20px;
         color:black;
         display:block; }"),
tags$style("#starttime {font-size:20px;
         color:black;
         display:block; }"),
tags$style("#endtime {font-size:20px;
         color:black;
         display:block; }"),
tags$style("#elapstime {font-size:20px;
         color:black;
         display:block; }")

)

#this runs it all.
shinyApp(ui = ui, server = server)

}

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.