Hello.
I am trying to get the shinywidgets selectizeGroup (for example) to update with the NEW values that have been entered into an editable data table. I cannot figure it out, I don't know what to do from here. I am still new so I apologize if the code is inefficient or otherwise wrong. I look forward to any help.
I know that there are two sets of filters here (DT and shinywidgets) but thats because I want more control over the filters than the basic options found in DT.
Thank you.
source_data <- iris
source_data$Date <- Sys.time() + seq_len(nrow(source_data))
# default global search value
if (!exists("default_search")) default_search <- ""
# default column search values
if (!exists("default_search_columns")) default_search_columns <- NULL
shinyApp(
ui = fluidPage(
fluidRow(box(
selectizeGroupUI(
id = "table_filter",
inline = TRUE,
params = list(
# City = list(
# inputId = "Petal.Length",
# title = "Petal.Length"),
ProductManager = list(
inputId = "Species",
title = "Species")
)
)
), width = "400"),
DT::dataTableOutput('dataTable')
),
server = function(input, output, session) {
reactive_values <- reactiveValues(source_data = NULL)
observe({
reactive_values$source_data <- source_data
})
#### this should be fed to output$dataTable so that the filters work
#### currently the filters "work" but the table disappears when edits are made
#### it seems like the data that builds the filters isn't being updated when edits are made
module_source_data <- callModule(
module = selectizeGroupServer,
id = "table_filter",
# data = source_data,
data = reactive_values$source_data,
vars = c("Species")
)
output$dataTable <- DT::renderDataTable(
module_source_data(),
# reactive_values$source_data,
editable = list(target = "cell", disable = list(columns = c(1, 2))),
filter = "top",
selection = 'none',
options = list(
scrollX = TRUE,
stateSave = FALSE,
searchCols = default_search_columns,
search = list(
regex = FALSE,
caseInsensitive = FALSE,
search = default_search
)
)
)
proxy <- dataTableProxy('dataTable')
observe({
input$dataTable_cell_edit
# when it updates, save the search strings so they're not lost
isolate({
# update global search and column search strings
default_search <- input$dataTable_search
default_search_columns <- c("", input$dataTable_search_columns)
# update the search terms on the proxy table (see below)
proxy %>%
updateSearch(keywords =
list(global = default_search,
columns = default_search_columns))
})
})
observeEvent(input$dataTable_cell_edit, {
info = input$dataTable_cell_edit
str(info)
i <- info$row
j <- info$col
v <- info$value
reactive_values$source_data[i, j] <<- DT:::coerceValue(v, reactive_values$source_data[i, j])
source_data[i, j] <<- DT:::coerceValue(v, reactive_values$source_data[i, j])
replaceData(proxy, source_data, resetPaging = FALSE, rownames = FALSE)
})
}
)