0

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")
```
  • 2
    Do you have `server: shiny` in your YAML header? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input we can copy/paste to run ourselves that can be used to test and verify possible solutions. – MrFlick Dec 02 '22 at 14:33
  • @MrFlick Do you mean `runtime: shiny`? – Stéphane Laurent Dec 02 '22 at 15:07
  • 2
    Ah no it's `shiny: server` . Never used Quarto yet. – Stéphane Laurent Dec 02 '22 at 15:08
  • thanks for your answers! I did add server: shiny in the YAML. @MrFlick I added a reproducible example in my original post. – mxfilerelatedcache Dec 05 '22 at 09:35

1 Answers1

0

I solved the problem. I still can't tell you what the problem was, but what helped was creating an entirely new .qmd file. That way, it rendered.

Edit: I found the culprit. It seems that | context:server doesnt work, while | context: server does. Always mind the spaces..