Not a Shiny programmer. Simple question. rhandsontable in Flexdashboard app. How to access a column updated by the user? Sample code:
---
title: "Test"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
require(dplyr)
require(tidyverse)
require(rhandsontable)
hour <- 1:24
required <- c(2, 2, 2, 2, 2, 2, 8, 8, 8, 8, 4, 4, 3, 3, 3, 3, 6, 6, 5, 5, 5, 5, 3, 3)
required <- as.integer(required)
on_duty <- as.integer(rep(0, 24))
start <- on_duty
df <- data.frame(hour, required, on_duty, start)
```
Inputs {.sidebar data-width=w}
-----------------------------------------------------------------------
```{r Inputs}
```
Column {data-width=200}
-----------------------------------------------------------------------
### Chart A
```{r}
global <- reactiveValues(df = df)
rHandsontableOutput("dftbl1")
output$dftbl1 = renderRHandsontable({
rhandsontable(global$df, selectCallback = TRUE, readOnly = FALSE)
})
```
So the code renders the table. A user could update the table by editing the table cells. But then how to reference the updated table to pass table columns to a function called with an actionButton? The complex examples I've found are difficult to decipher. Appreciate any feedback. SteveM
you can use
hot_to_r
as into get access to the current state of the table including modifications from the user.
req
is needed becausehot_to_r
can't deal withNULL
s.table_id
should be the output-id you use for the return value ofrenderRHandsontable
.The complex examles you are referring to (like this one, #64-81) allow a two-way connection of the tables in the sense that they can be updated both from the user and from the server. In this simple setup I outlined here however,
modified_table
is created withreactive
so it can only be updated by the user.I totally agree that this package could be made more user friendly by allowing
NULL
inhot_to_r
and by automatically callingrhandsontable
inrenderRHandsontable
if the return value is adata.frame
but this is what you will have to work with.Here is a full app demonstrating this setup
In order to access a specific column, you can use
modified_table()$column_name
inside a reactive context.