Using the following code I obtain the selection of each row for the column species_selector, however I see that only works the first time that I click on the "GENERATE DATA" button...
library(shiny)
library(DT)
ui <-
tabItem("single_item_pricing2", class = "active",
fluidRow(
title = 'Selectinput column in a table',
DT::dataTableOutput('foo'),
verbatimTextOutput('sel'),
textOutput("selected_var"),
box(width = 12,
column(6,
actionButton("btnExecuteModel", label = "GENERATE DATA"),
),
)
)
)
server <- function(input, output, session) {
data <- data.frame()
observeEvent(input$btnExecuteModel, {
data <<- head(iris, 5)
for (i in 1:nrow(data)) {
data$species_selector[i] <<- as.character(selectInput(paste0("sel", i), "", choices = unique(iris$Species), width = "100px"))
}
output$foo = DT::renderDataTable(data,
escape = FALSE, selection = 'none', server = FALSE,
options = list(dom = 't', paging = FALSE, ordering = FALSE),
callback = JS("table.rows().every(function(i, tab, row) {
var $this = $(this.node());
$this.attr('id', this.data()[0]);
$this.addClass('shiny-input-container');
});
Shiny.unbindAll(table.table().node());
Shiny.bindAll(table.table().node());")
)
output$sel = renderPrint({
str(sapply(1:nrow(data), function(i) input[[paste0("sel", i)]]))
})
})
}
shinyApp(ui, server)
Could someone explain to me how to solve this issue? Is like after the first button click, the value of (for example input[["sel1"]]) maintain just the original selection and doesn't update after.
Thanks in advance.