...
(There is a minrep at the bottom of this post)
I am trying to make an app where the user can view various subsets of a large data frame, can make edits to that dataframe and can then save the dataframe with the changes to a list. This would be a list of tables. But I cannot find a way of storing the tables once they have been edited, I have tried using lapply, but this is not working.
Heres the problem, and how ive tried to solve it:
I have the following subset arguments which form a reactive object called guest_list()
:
guest_list <- reactive({
referrals %>%
###IMPORTANT PART
subset(
((
!`sr-id` %in% cridRemoved$vec) &
grepl("empowering independence", .$service, ignore.case = T) &
tab1QLogic()[[as.numeric(input$question)]]
)) %>%
###UNIMPORTANT PART (just cleans up the result)
mutate_if(is.Date,~format(.,"%d-%m-%Y")) %>%
select(!c(region, `interview (offered)`, interview, interviewer, `data protection`, consent, `rejected to`, `first contact`, received)) %>%
arrange(`c-id`)
})
The arguments in the 'important part' make guest_list()
into a way of subsetting a data frame referrals
based on radio button input input$question
which toggles between different booleans from a list called tab1QLogic()
which has 18 elements.
When the user is done examining the different subsets and removing elements by making some unique ids ( sr-id
) FALSE by appending them to cridRemoved$vec
; I want them to be able to store the final results in a list of 18 elements (one for each subset defined by each boolean in tab1Logic
) .
To do this I have tried to use lapply
to run a list-creation function across each boolean in tab1Logic
, wrapped in an observeEvent
so that it can be triggered from a button in the UI. See the following:
summary <- reactiveValues(
summary = list()
)
observeEvent(input$storeTab1, {
summary$tab1 <- lapply(1:18,
function(x){
referrals %>%
###IMPORTANT PART
subset(
((!`sr-id` %in% cridRemoved$vec) &
grepl("empowering independence", .$service, ignore.case = T) &
tab1QLogic()[[x]])) %>%
###UNIMPORTANT PART
mutate_if(is.Date,~format(.,"%d-%m-%Y")) %>%
select(!c(region, `interview (offered)`, interview, interviewer, `data protection`, consent, `rejected to`, `first contact`, received)) %>%
arrange(`c-id`)
}
)
})
#### THIS OUTPUT IS THERE TO SEE IF THE LAPPLY HAS DONE ANYTHING
output$test <- renderTable(summary$tab1[[1]])
The main thing wrong with this is that it doesn't work, no errors get thrown up it just doesn't nothing.
The other thing is that I don't like that I have had to repeat the arguments on the guest_list()
as a function in lapply.
Below is a link to a google drive with a minrep of the whole app, I have replaced 'referrals' with 'redacted_referrals' and have edited the select functions so that there are no error-producing unrecognised (redacted ) columns, aside from that the minrep is faithful to the original:
https://drive.google.com/drive/folders/1gKZLAdXeec-DvnX-96nyWqQ7p722JuSy