You can achieve what you want by rendering the Handsontables accordingly. You can use an observeEvent that checks for changes in the handsontable depending on the modified column and set the desired columns to readOnly. For this purpose, I suggest using reactive values and in this way, you can get the column that was changed
simply by column_index = input$hot$changes$changes[[1]][[2]].
Hope this helps.
library(rhandsontable)
library(shiny)
ui <- fluidPage(
mainPanel(
rHandsontableOutput("hot")
)
)
server = function(input, output, session){
df <- data.frame(a = rnorm(10), b = rnorm(10))
values <- reactiveValues(data = df)
observeEvent(
input$hot$changes$changes, # observe any changes in the cells of the rhandsontable
{
column_index =input$hot$changes$changes[[1]][[2]] # get the index of the column that was changed
values$data <- hot_to_r(input$hot)
if(column_index == 1){
output$hot <- renderRHandsontable({
rhandsontable(values$data) %>%
hot_col('a', readOnly = T)
})
}
else{
output$hot <- renderRHandsontable({
rhandsontable(values$data) %>%
hot_col('b', readOnly = T)
})
}
}
)
output$hot <- renderRHandsontable({
rhandsontable(values$data)
})
}
shinyApp(ui, server)