#' Module SERVER for Input operations Data
#'
#' @param id Module Identification
#' @param op_data Operation's Data
#'
#' @return shiny server
#' @export
op_data_input_server <- function(id, op_data) {
moduleServer(id, function(input, output, session) {
# Output the data-table based on the data-frame (and make it editable)
output$my_datatable <- DT::renderDT({
DT::datatable({op_data$data},
caption = "Operations Data:",
editable = TRUE,
colnames = c('P1 (Bar)', 'P2 (Bar)', 'Flow (m3/h)'),
options = list(dom = 't'))
})
# When there is any edit to a cell, write that edit to the initial data-frame
# Check to make sure it's positive, if not convert
observeEvent(input$my_datatable_cell_edit, {
# Get values
info = input$my_datatable_cell_edit
i = as.numeric(info$row)
j = as.numeric(info$col)
k = as.numeric(info$value)
# Convert to positive if negative
if(k < 0){ k <- k * -1}
# Write values to reactive
op_data$data[i,j] <- k
})
})
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.