This question extends from another question that correctly explains how to use a button to subset a dataframe based on a slider.
I need a bit more specific help with my real problem.
I have a function "transition_matrix" in my server.R that takes 2 inputs: (a) a dataframe containing product information and (b) a date. I pre-load the dataframe as fixed but then allow the user to change the date. So, when the user changes the date, the function executes for the given dataframe and the selected date.
The code thus far:
server.R
shinyServer(function(input, output) {
bigmatrix <- reactive({
transition_matrix(capital_summary_cum, ceiling_date(as.Date(input$datebox),"month")-1)
})
output$balance_matrix <- renderTable({
balances_ <- bigmatrix()[1:(default_state +2),] %>%
round(digits = 0) %>%
format(big.mark = ",")
transition_matrix <- function(df1, date1){
date2 <- ceiling_date(as.Date(AddMonths(date1,1)),"month")-days(1)
...
...
What I want to do next is to allow the user to subset the dateframe as well. To do this I offer a group of checkboxes which represent products. So, in addition to the date, the user can also select a subset of products on which to perform the aforementioned function.
The problem is that the function takes approx 1.5 seconds to execute, so each time the user will check a box (of which there are approx 40) the function will be called creating an unwanted 1.5 sec delay.
I rather want to isolate (?) the checkboxes to allow the user to select the desired list of products until a button is clicked. Once the button is clicked I want to subset the dataframe based on the selected checkboxes, and only then feed this into the function. I really would like the date input to remain "fully reactive" so that i don't have to press the button each time the date is also changed.
How can I add a button that will subset my dataframe based on selected checkboxes and automatically call the function with the selected date?
eventReactiveinstead ofreactivefor yourbigmatrixfunction? Note that you needinput$dateboxas the first argument foreventReactive. If this does not give you the desired outcome, perhaps the checkboxes are inspected somewhere else in your code. - Kota Moriisolatefor the checkboxes so that the shiny ignores the update in those. Shiny will ignore the isolated objects, so it does not refresh the page when they are updated. I don't see checkboxes in your code, but guess they are somewhere intransition_matrixfunction. - Kota MoriactionButtonand refers to it within yourbigmatrixfunction. The button does not affect the calculation outcome itself, but by doing so the function is triggered when the button is clicked. - Kota Moribigmatrixis supposed to return a dataset (which is calculated fromtransition_matrixfunction). I don't believe I can just randomly reference a button inbigmatrixbecause it is expecting a dataset and nothing more? If I am misunderstanding, then how and where exactly do I add a reference to the actionButton? - gmarais