I want to insert data in SQL Table based on user input. I need to add radiobutton (or checkbox) in each row of a column (let's say 'FLAG'). Value will be flagged 1 when user selects checkbox of a row. The whole row against the checkbox should be entered into SQL table.
I am able to update check box in each row. See the update code below -
library(shiny)
library(DT)
# FETCH DATA
cn = odbcDriverConnect(connection='driver={SQL SERVER}; Server=xxx; database=xxx;
port=xxxx; uid=xxx; pwd=xxxx')
mydata = sqlQuery(cn,"SELECT X1, X2,X3,X4 FROM DBO.Table1")
mydata$id = 1:nrow(mydata)
runApp(
list(ui = pageWithSidebar(
headerPanel('Sample FWA Table'),
sidebarPanel(
checkboxGroupInput('show_vars', 'Columns to show:', names(mydata),
selected = names(mydata))
),
mainPanel(
DT::dataTableOutput("mytable")
)
)
, server = function(input, output, session) {
rowSelect <- reactive({
paste(sort(unique(input[["rows"]])),sep=',')
})
output$mytable = DT::renderDataTable({
addCheckboxButtons <- paste0('<input type="checkbox" name="row', mydata$id, '" value="', mydata$id, '">',"")
DT::datatable(cbind(Flag=addCheckboxButtons, mydata[, input$show_vars, drop=FALSE]),filter="top",
selection="multiple", options = list(orderClasses = TRUE,
lengthMenu = c(5, 10, 25, 50), pageLength = 5,
callback = JS("function(table) {
table.on('change.dt', 'tr td input:checkbox', function() {
setTimeout(function () {
Shiny.onInputChange('rows', $(this).add('tr td input:checkbox:checked').parent().siblings(':last-child').map(function() {
return $(this).text();
}).get())
}, 10);
});
}")),escape = FALSE,
)
}
)
}
)
)
I want to know how to INSERT INTO in SQL based on checkbox selection.
...