Skip to content

Commit

Permalink
fix update of table choices
Browse files Browse the repository at this point in the history
  • Loading branch information
arunge committed Jan 8, 2025
1 parent d5a37b4 commit 66fa63e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
30 changes: 22 additions & 8 deletions R/02-importData-mergeData.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,18 @@ mergeDataServer <- function(id, mergeList) {
tableIds(extractTableIds(mergeList()))

tableChoices <- extractMergeListChoices(mergeList(), addIDs = TRUE)
updateSelectInput(session,
"tableX",
choices = tableChoices,
selected = unlist(tableChoices)[1])
updateSelectInput(session,
"tableY",
choices = tableChoices,
selected = unlist(tableChoices)[2])
updateSelectInput(
session,
"tableX",
choices = tableChoices,
selected = extractLastSelected(input$tableX, choices = tableChoices)
)
updateSelectInput(
session,
"tableY",
choices = tableChoices,
selected = extractLastSelected(input$tableY, choices = tableChoices, idDefault = 2)
)
})

output$nRowsTableX <- renderText({
Expand Down Expand Up @@ -290,6 +294,16 @@ extractTableData <- function(mergeList, tableName) {
mergeList[[tableName]]$data
}

extractLastSelected <- function(thisInput, choices, idDefault = 1) {
if (!is.null(thisInput) && thisInput != "") {
lastSelected <- thisInput
} else {
lastSelected <- unlist(choices)[idDefault]
}

lastSelected
}

extractMergeListChoices <- function(mergeList, addIDs = FALSE) {
getNames <- function(dataList) {
if (length(dataList) == 0)
Expand Down
13 changes: 7 additions & 6 deletions R/02-importData-prepareData.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ prepareDataServer <- function(id, mergeList) {
observeEvent(mergeList(), ignoreInit = TRUE, {
req(length(mergeList()) > 0)
logDebug("Updating input select from mergeList")

choices <- extractMergeListChoices(mergeList())
updateSelectInput(session,
"dataToPrep",
choices = choices,
selected = unlist(choices)[length(unlist(choices))])
updateSelectInput(
session,
"dataToPrep",
choices = choices,
selected = extractLastSelected(input$dataToPrep, choices = choices)
)
})

observe({
logDebug("Entering preparedData")
# update here changes of input$dataToPrep & changes of mergeList -> takes
# always most recently updated data
req(length(mergeList()) > 0)
preparedData$data <- NULL

Expand Down

0 comments on commit 66fa63e

Please sign in to comment.