Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rhandsontable hide columns for a shiny app

I use

output$hot <- renderRHandsontable(rhandsontable(DF))

to get a table.

All works fine but I would like to allow the user to select certain columns only (implemented with shiny::updateSelectizeInput()). the data should then be updated in the full data table and not only in the columns selected. I googled but could only find a very bad description in java. Can someone help me out with this?

as requested an example:

 DF = data.frame(matrix(rnorm(20), nrow=10)) 
 rhandsontable(DF)
like image 535
Walde Avatar asked Feb 03 '26 19:02

Walde


1 Answers

This is a few years late, and I will note that I don't think this will completely solve the issue as it doesn't use "updateSelectizeinput()" as requested by the OP, plus I must not be handling the select input correctly as one column always shows, but for anyone looking for a start, here is an example:

library(shiny)
library(rhandsontable)

ui <- fluidPage(
  selectInput("Select", "Select", names(mtcars), multiple = T, selected = names(mtcars)),
  rHandsontableOutput("cars")
)

server <- function(input, output, session) {
  DF<-reactiveValues(DF = mtcars, Select = NULL)
  observeEvent(input$Select,{
    DF$Select <- input$Select
  })
  output$cars<-renderRHandsontable({
    rhandsontable(DF$DF, rowHeaders = NULL)%>%
      hot_cols(colWidths = ifelse(names(DF$DF) %in% DF$Select == T, 150, 0.1))
  }) 
}

shinyApp(ui, server)

It uses 0.1 as a column width to effectively hide the column, leaving the original data frame in tact.

like image 116
Silentdevildoll Avatar answered Feb 06 '26 08:02

Silentdevildoll