I'm trying to display an interactive table using the reactable package in an embedded Shiny app within my Quarto markdown document. However, I can't get it to work. My code is as follows:
I define the input here:
selectizeInput('OP', "Label:",choices = choices)
and then create a table according to their specification here:
#|context: server
output$table <- renderReactable({
reactable(
tweets %>%
filter(OP==input$OP) %>%
group_by(original_hash) %>%
mutate(n=n()) %>%
filter(n>1) %>%
arrange(date) %>%
mutate(duration=last(date)-first(date)) %>%
summarise(n=mean(n),duration=mean(duration)) %>%
mutate(days = as.numeric(duration, units = 'days'),
minutes = as.numeric(duration, units = 'mins')) %>%
arrange(desc(n))
)
})
and visualise it here:
reactableOutput("table")
However, I get the following error:
Error in output$table <- renderReactable({ : object 'output' not found
Calls: .main ... withVisible -> eval_with_user_handlers -> eval -> eval
I don't get it. It seems the problem is related to the usual notation in Shiny apps with
server <- function(input, output, session) {
output$table <- (...)
}
vs. the contexts that Quarto apps with embedded Shiny apps work with:
#|context: server
Any help appreciated!
After much googling and trying (also with the server <- function(...)) I still couldn't get it to work.
Here is a reproducible example:
---
format: html
server: shiny
---
## Introduction
```{r}
#| context: data
#| include: false
library(dplyr)
library(reactable)
users <- c("user1","user2","user3")
```
```{r}
#|context: server
library(reactable)
n <- 6
dat <- data.frame(id=1:n,
date=seq.Date(as.Date("2020-12-26"), as.Date("2020-12-31"), "day"),
group=rep(LETTERS[1:2], n/2),
age=sample(18:30, n, replace=TRUE),
type=factor(paste("type", 1:n)),
x=rnorm(n))
output$tbl <- renderReactable({
reactable(dat)
})
```
```{r}
reactableOutput("tbl")
```