I have a number of numericInputs put into several columns of a DT datatable. I would like to allow users to click a button, which then copies inputs from the first column to the other columns. I'm able to make this work for numericInputs that are not part of a datatable, but nothing happens to numericInputs inside of a datatable. A simplified example of my problem is given below. I also include a working example for a standalone numericInput, which is not part of a datatable, to demonstrate the behavior I'm looking for.
library(shiny)
library(DT)
shinyApp(
server = shinyServer(function(input, output, session) {
output$Table <- DT::renderDataTable({
observeEvent(input$button1, {
v <- input$Number.1.1
updateNumericInput(session,"Number.2.1", value = v)
})
temp <- data.frame(c(1:5))
temp$Numbers.1 <- ""
temp$Numbers.2 <- ""
sapply(1:5, FUN = function(i){
temp$Numbers.1[i] <<- as.character(numericInput(paste0("Number.1.", i), "", value = NULL, min = 0, max = 10, step = 0.01))
})
sapply(1:5, FUN = function(i){
temp$Numbers.2[i] <<- as.character(numericInput(paste0("Number.2.", i), "", value = NULL, min = 0, max = 10, step = 0.01))
})
datatable(temp,escape = FALSE, rownames = FALSE, options = list(sort = FALSE, paging = FALSE, searching = FALSE))
})
observeEvent(input$button2,{
v <- input$Number.3
updateNumericInput(session,"Number.4", value = v)
})
}),
ui = fluidPage(
br(),
actionButton("button1","Copy"),
dataTableOutput("Table"),
br(),
actionButton("button2","Copy"),
numericInput("Number.3", "Number 3", value = NULL, min = 0, max = 10, step = 0.1),
numericInput("Number.4", "Number 4", value = NULL, min = 0, max = 10, step = 0.1)
)
)
I have also tried placing the observeEvent outside of the renderDataTable, but that was no help. Since the button works fine for standalone numericInputs, I'm guessing this is some sort of scoping issue, but I've been unable to figure out how to resolve it.
Thanks in advance for any help!