# load the package:
library(handsontable)
home
R interface to the Handsontable JavaScript library v6.2.2 (MIT license).
create interactive spreadsheet-like data grids with data validation, sorting, and filtering.
installation
# install from CRAN
install.packages("handsontable")
# or install from GitHub
::install_github("kennedymwavu/handsontable") devtools
quick example
# basic table:
handsontable(mtcars[1:5, ], adaptiveHeight = TRUE)
# col specific config + validation + context menu:
handsontable(
1:8, ],
iris[adaptiveHeight = TRUE
|>
) hot_col(
col = "Species",
type = "dropdown",
source = c("setosa", "versicolor", "virginica")
|>
) hot_validate(
col = 1:4,
type = "numeric",
min = 0
|>
) hot_context_menu()
- right-click to see the context menu
- try entering an invalid value (like a letter) in the first 4 columns.
shiny integration
library(shiny)
<- fluidPage(handsontableOutput("table"))
ui
<- function(input, output) {
server $table <- renderHandsontable({
outputhandsontable(iris[1:10, ]) |>
hot_context_menu()
})
# detect changes:
observeEvent(input$table, {
<- hot_to_r(data = input$table)
updated_data cat("Updated data:\n")
print(updated_data)
# use updated data...
})
}
shinyApp(ui, server)
similar packages
{rhandsontable}
the rhandsontable package provides an R interface to handsontable and has been a valuable tool for the R community. however, it hasn’t been actively maintained in recent years.
{handsontable}
was developed to ensure active maintenance with regular updates, bug fixes, and feature enhancements that the community needs.