I have an issue with what appears to be caching in a Shiny app, and I cannot find a workaround. I'm hoping someone else can.
The error occurs in the following code:
# Display a selected record for editing purposes.
output$edit_committee <- renderUI(
{
# There has to be data, and a row must be selected.
req(display$Committee)
req(input$display_committee_rows_selected)
# The user must be an administrator.
req(admin())
if (admin()) {
# Get the selected row.
record <- database$Committee[input$display_committee_rows_selected, , drop = FALSE]
# Display it.
tags <- editCommitteeTagList(record)
do.call(tagList, tags)
} else {
modalDialog(title = "OOPS!",
"Sorry, only users with administrator privilege can edit the committee roster."
) |> showModal()
req(admin())
}
}
)
In the UI, "edit_committee" identifies a uiOutput instance that display a bunch of input controls (text fields and check boxes), while "display_committee" identifies a DTOutput instance that shows the data frame named "display$Committee" (part of a list of data frames). There is another list of data frames containing "database$Committee". The "database" list is tables pulled from an external database; the "display" list has modified versions of those tables adapted for display via DTOutput.
The bug manifests as follows. The user selects a row in the displayed table, edits it (via the input controls in the uiOutput instance) and submits it to be saved in the database. After the save occurs, the app pulls the data from the database and updates database$Committee, then uses that to update display$Committee. Crucially, I have confirmed during debugging that both those updates do occur.
Now the user clicks on a row in the DTOutput instance, and the code above populates the edit controls using that row. If the user clicks on any row other than the one just edited, the edit controls are correctly populated. If the user clicks the row last edited, the edit controls are populated using the previous version of the data, even though database$Committee is confirmed to have been update and the correct (post-update) version of the data is showing in the DTOutput. So apparently the line
record <- database$Committee[input$display_committee_rows_selected, , drop = FALSE]
is accessing a cached version rather than the current version of database$Committee (or at least a cached version of the edited row).
Is there any way to force use of the current version of the row?