I've been following the instructions here for creating an editable dataTable in R Shiny. Now I want to update the user's choices for another input, but the values are not updating in pickerInput()
, as they correctly do in the renderPrint()
function.
Can anyone enlighten me on the best way to use updateSelectInput()
when trying to get objects stored within reactiveValues()
? Thanks in advance.
library(DT)
iris$Species = as.character(iris$Species)
shiny::shinyApp(
ui <- fluidPage(
DTOutput('x1'),
pickerInput(
inputId = "x2",
label = "",
choices = unique(iris$Species)
),
verbatimTextOutput("print")
),
server <- function(input, output, session){
x = reactiveValues(df = NULL)
observe({
x$df = iris
})
output$x1 = renderDT(
x$df,
rownames = F,
editable = T)
proxy = dataTableProxy('x1')
observeEvent(input$x1_cell_edit, {
info = input$x1_cell_edit
str(info)
i = info$row
j = info$col + 1
v = info$value
x$df[i, j] <- isolate(DT::coerceValue(v, x$df[i, j]))
updateSelectInput(session, "x2", choices = unique(x$df$Species)) #NOT BREAKING, BUT NOT WORKING
})
output$print <- renderPrint({
unique(x$df$Species)
})
}
)```