cell edit should reflect in other column

Capture
table is output of renderdatatable.
e is an editable column
when we enter the value of e then f should change

Hi,

Here is an example using DT and its proxy function

library(shiny)
library(DT)

ui <- fluidPage(
  DTOutput("myTable")
)

server <- function(input, output, session) {

  #Get the initial data
  tableData = reactiveValues(
    myData = data.frame(
      x = 1:10,
      even = c("no", "yes")
  ))
  
  #Create a proxy for updating table
  proxy = dataTableProxy('myTable')
  
  #Render tablle
  output$myTable = renderDT({
    
    #Proxy will update data so only first time render it 
    #That why we put it in isolate
    isolate(tableData$myData)
    
  }, editable = "cell")
  
  
  #Detect cell edits
  observeEvent(input$myTable_cell_edit, {
    
    cell = input$myTable_cell_edit
    
    #Only do something if column 1 is changed
    if(cell$col == 1){
      
      #Update the data frame with new value and edit other colum
      tableData$myData[cell$row,] = list(
        as.integer(cell$value),
        ifelse(as.integer(cell$value) %% 2 == 0, "yes", "no")
      )
      
      #Push the changes back through proxy
      replaceData(proxy, tableData$myData)
        
    }
    
  })
  
}

shinyApp(ui, server)

In this example, when you change the number in column x, even will update to check if it's even or not.

Hope this helps,
PJ

will i be able to use renderdatatable instead of renderDT?

Hi,

I think you have to use DT for this as it is more powerful. At least that's the one I always use.

PJ

is it possible without using reactivevalues?

how to pass the entire dataset in reactivevalues?

library(shiny)
library(tidyverse)
library(DT)

some_data <- data.frame(e=1:8)

ui <- DTOutput('tbl')

server <- function(input, output, session) {

some_reactive <- reactive(some_data)

modified_reactive <- reactive({
mutate(some_reactive(),
f=if_else(e<4,"yes","no"))
})

output$tbl <- renderDT( modified_reactive() )
}

shinyApp(ui, server)

can you help with this ?
observeEvent(input$modified_reactive_cell_edit, {
f=if_else(e>100,"yes","no")

})
i tried this also

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.