Background : I have a shiny DT in a modaldialog box conataining radio buttons in columns, I want to do some processing based on the selections of radio button in DT
Problem : I am unable to figure out how to extract the value of the selected radiobutton from DT
Below is the reproducible exmaple for the same.
library(shiny)
library(DT)
library(data.table)
library(shinyWidgets)
shinyApp(
ui = fluidPage(
title = 'Radio buttons in a table',
actionBttn(inputId = "btnContinue",label = "Continue",style = "material-flat")
),
server = function(input, output, session) {
dtWithRadioButton <- reactiveValues(dt = NULL)
observeEvent(input$btnContinue,{
m = matrix(
as.character(1:5), nrow = 12, ncol = 5, byrow = TRUE,
dimnames = list(month.abb, LETTERS[1:5])
)
for (i in seq_len(nrow(m))) {
m[i, ] = sprintf(
'<input type="radio" name="%s" value="%s"/>',
month.abb[i], m[i, ]
)
}
dt <- data.table(m)
v <- LETTERS[1:12]
dt <- cbind(v,dt)
dtWithRadioButton$dt <- dt # setting reactive value
showModal(modalDialog(
size = "l",easyClose = F,fade = T,
renderDataTable(datatable(dt, selection = "none",escape = FALSE, options = list(dom = 't') , rownames = F)),
footer = tagList(
actionBttn(inputId = "btnCancel",label = "Cancel",style = "float",size="sm",color="warning"),
actionBttn(inputId = "btnProcess",label = "Process",style = "float",size="sm",color="success")
)
))
})
observeEvent(input$btnProcess,{
dt <- dtWithRadioButton$dt # accessing the reactive value
# do some processing based on the radio button selection
})
observeEvent(input$btnCancel,{
removeModal(session)
})
}
)
On click of 'Continue' button a pop-up containing a shiny DT with radio button is displayed to user. Once user makes selection using radio button. I want to run a process on click of btnProcess