I am trying to build a Shiny app that allows the user to subset a range of cells from a dataset using the rhandsontable
package. There is a working example here, but I can't find the equivalent in R.
This is what I have so far, without sucess:
library(shiny)
library(rhandsontable)
ui <- fluidPage(
rHandsontableOutput("hot_original"),
rHandsontableOutput("hot_subset")
)
server <- function(input, output) {
# Create a sample dataset
df <- data.frame(
x = 1:10,
y = letters[1:10],
z = rnorm(10)
)
output$hot_original <- renderRHandsontable({
rhandsontable(df)
})
observeEvent(input$hot_original, {
# Get the selected range of cells
hot_col <- hot_to_r(input$hot_original)
# Subset the original dataset using the selected range of cells
subset_df <- df[hot_col$rows, hot_col$cols]
# Display the subset in a separate rhandsontable
output$hot_subset <- renderRHandsontable({
rhandsontable(subset_df)
})
})
}
shinyApp(ui, server)
The issue is that hot_col
does not contain any information about the cell selection, and the reactive is not triggered when a user selects a cell.