4

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)
Walde
  • 45
  • 8
  • 2
    Please clarify with a simple example. – Xiongbing Jin Oct 12 '16 at 17:42
  • here is an example: DF = data.frame(matrix(rnorm(20), nrow=10)) rhandsontable(DF) I just want to show X2 but be able to update the whole table. i.e. I do not want to merge X2 after I updated the data.frame. – Walde Oct 13 '16 at 05:49
  • Silentdevildoll gave an elegant solution. Still, I do not understand why for instance you don't want to use a simple `cbind()` which is not time consuming in order to update the whole table. Even with an `order = T` within your rhandsontable (which only orders client side), original order will be retunred using `hot_to_r()` therefore no need for `merge()` which may be time consuming. – yeahman269 Apr 28 '21 at 09:08

1 Answers1

1

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.

Silentdevildoll
  • 1,187
  • 1
  • 6
  • 12
  • rhandsontable is re-rendered each time user modify its selection, therefore why not simply use a `select` statement within `renderRHandsontable`? What would be great would be to preserve table edition when user changes the selection (i.e. not re-render the table, just modify the table display). – yeahman269 Apr 28 '21 at 09:26