admin管理员组

文章数量:1402851

I am building an interactive Quarto Dashboard using Shiny in RStudio. My app is fully functional—it renders perfectly, and the interactive features work as expected. However, every time I run the app, I see the following error in the RStudio console:

Error: object 'output' not found

I am using code chunks with execution contexts in my Quarto document to structure the code. Below is a simplified example that demonstrates the issue. My actual project follows the same Quarto-Shiny setup.

---
title: "proj"
format: dashboard
server: shiny
---

```{r}
#| label: load-packages
#| context: setup
#| message: false

library(tidyverse)
library(shiny)
library(rnaturalearth)
library(rnaturalearthdata)
library(leaflet)
```

``` {r}
#| label: prep-data
#| context: setup

world_map_df <- ne_countries(scale = "medium", returnclass = "sf") |>
  filter(name != "Antarctica")
```
## {.sidebar}

```{r}
checkboxGroupInput("income_grp", "Income group", c("High income: OECD" = "1. High income: OECD", "High income: nonOECD" = "2. High income: nonOECD", "Upper middle income" = "3. Upper middle income", "Lower middle income" = "4. Lower middle income", "Low income" = "5. Low income"))
```

## Map

```{r}
leafletOutput("map")
```

```{r}
#| context: server

output$map <- renderLeaflet({
  world_map_df |>
    leaflet() |>
    addTiles()
})

map_filtered <- reactive({
    subset(world_map_df, income_grp %in% input$income_grp)
})

observe({
  pal <- colorNumeric(palette = "YlGn", domain = world_map_df$gdp_md)

  leafletProxy("map", data = map_filtered()) |>
    clearShapes() |>
    addPolygons(color = "black", fillColor = ~ pal(gdp_md), weight = .5, opacity = 1, fillOpacity = .7, label = ~ paste0("GDP: ", gdp_md))
})
```

What I've Tried:

  • Checked other Stack Overflow threads on Quarto and Shiny execution contexts.

  • Consulted AI assistants, but they did not resolve the issue.

  • Printed ls(environment()) inside the server context to check if output is available (it does not appear).

Questions:

Why does this error appear even though the app is fully functional? Is there a Quarto-specific issue with how output is initialized? How can I prevent this error from showing in the console?

本文标签: r39Error object output not found39 despite fully functional appStack Overflow