Hello,
I have the following editable DT table. Sepal.Length
and Sepal.Width
have been restricted so no changes can be made to them. However, Petal.Length
needs to be changeable but with rules checking that a valid input was provided. A valid input for Petal.Length
by row should not be less than the min
value and not more than the max
provided as part of the table.
library(shiny)
library(DT)
library(tidyverse)
shinyApp(
ui = fluidPage(
DTOutput('x1')
),
server = function(input, output, session) {
x = reactiveValues(df = NULL)
observe({
df <- iris
df <- df %>% mutate(min = 1)
df <- df %>% mutate(max = max(sample(1:10,5)))
x$df <- df
})
output$x1 = renderDT(x$df, selection = 'none', editable = list(target = 'cell', disable = list(columns = c(1,2))))
proxy = dataTableProxy('x1')
observeEvent(input$x1_cell_edit, {
info = input$x1_cell_edit
str(info)
i = info$row
j = info$col
v = info$value
x$df[i, j] <- isolate(DT::coerceValue(v, x$df[i, j]))
})
reactive_df <- reactive({
temp <- x$df %>% mutate(sum = Sepal.Length + Sepal.Width + Petal.Length)
temp})
}
)