enable comments in RHandsonTable but disable context menu?

414 Views Asked by At

I want to add comments to my rhandsontable but I don't want to enable the context menu (that allows user to add and remove rows, edit comments, etc.). How can I do this?

library(rhandsontable)

vt <- mtcars
modrows <- c(3,6,9)
modtext <- LETTERS[1:3]
vttooltips <- matrix(ncol = ncol(vt), nrow = nrow(vt))
vttooltips[modrows, 2] <- modtext

rhandsontable(vt, 
              comments = vttooltips) %>% 
  hot_context_menu(allowRowEdit = FALSE, allowColEdit = FALSE, 
                   allowReadOnly = FALSE, allowComments = TRUE, 
                   allowCustomBorders = FALSE, customOpts = list())
2

There are 2 best solutions below

0
On BEST ANSWER

Here's the solution, thank to @DzimitryM at https://github.com/jrowen/rhandsontable/issues/334

t <- rhandsontable(vt, 
              comments = vttooltips)
t$x$contextMenu <- list()
t
5
On

Is this what you want?

library(shiny)
library(rhandsontable)

vt <- mtcars
modrows <- c(3,6,9)
modtext <- LETTERS[1:3]
vttooltips <- matrix(ncol = ncol(vt), nrow = nrow(vt))
vttooltips[modrows, 2] <- modtext

shinyApp(
  ui = fluidPage(
    rHandsontableOutput('table')
  ),
  server = function(input, output) {
    tbl <- rhandsontable(vt, readOnly=TRUE,
                         comments = vttooltips)
    output$table <- renderRHandsontable(tbl)
  }
)

There is more info about combining Rhandsontable and shiny here.