positron icon indicating copy to clipboard operation
positron copied to clipboard

Geomap can not be rendered in Positron, Rstudio is normal

Open ntluong95 opened this issue 9 months ago • 2 comments

System details:

Positron and OS details:

Positron Version: 2025.06.0 (system setup) build 91 Code - OSS Version: 1.99.0 Commit: 472340438bbedac9a406cdb308b56e2e38e57249 Date: 2025-05-16T03:47:15.293Z Electron: 34.3.2 Chromium: 132.0.6834.210 Node.js: 20.18.3 V8: 13.2.152.41-electron.0 OS: Windows_NT x64 10.0.26200

Interpreter details:

R 4.4.2

Describe the issue:

Plot is not rendered in Plots pane

Image

Steps to reproduce the issue:

pacman::p_load(
  raster,
  sf,
  geodata,
  ggpattern,
  tidyverse
)

# 1. Load Sweden level-1 counties
swe_gadm <- gadm(country = "SWE", level = 1, path = tempdir())
swe <- st_as_sf(swe_gadm)

# 2. Build mock prevalence across years
years <- 2008:2018
prevalence_df <- expand.grid(
  NAME_1 = swe$NAME_1,
  Year = years,
  stringsAsFactors = FALSE
) %>%
  mutate(
    rate_per100k = runif(n(), 0, 30), 
    category = case_when(
      rate_per100k <= 2.5 ~ "≤2.5 (suppressed)",
      rate_per100k <= 5 ~ "2.5–5",
      rate_per100k <= 10 ~ "5–10",
      rate_per100k <= 20 ~ "10–20",
      TRUE ~ ">20"
    ),
    category = factor(
      category,
      levels = c("2.5–5", "5–10", "10–20", ">20", "≤2.5 (suppressed)")
    )
  )

# 3. Join spatial + prevalence data
swe_map <- left_join(prevalence_df, swe, by = "NAME_1")
swe_map <- st_as_sf(swe_map) # ensure it stays an sf object

# 4. Plot small multiples
ggplot() +
  # Hatched for suppressed
  geom_sf_pattern(
    data = filter(swe_map, category == "≤2.5 (suppressed)"),
    aes(geometry = geometry),
    pattern = "stripe",
    pattern_density = 0.6,
    pattern_spacing = 0.02,
    pattern_angle = 45,
    fill = "grey90",
    colour = "white"
  ) +
  # Solid fills for the rest
  geom_sf(
    data = filter(swe_map, category != "≤2.5 (suppressed)"),
    aes(geometry = geometry, fill = category),
    colour = "white"
  ) +
  scale_fill_manual(
    name = "Prevalence\n(cases per 100 000)",
    values = c(
      "2.5–5" = "#CCCCCC",
      "5–10" = "#999999",
      "10–20" = "#666666",
      ">20" = "#333333"
    )
  ) +
  facet_wrap(~Year, ncol = 4) +
  labs(
    title = "Prevalence in Sweden by County (2008–2018)",
    subtitle = "Counts per 100 000; ≤2.5 per 100 000 suppressed"
  ) +
  theme_minimal() +
  theme(
    strip.text = element_text(size = 10),
    axis.text = element_blank(),
    axis.ticks = element_blank(),
    panel.grid = element_blank(),
    legend.position = "bottom"
  )



Expected or desired behavior:

Plot is rendered normally in Plots pane

Image

ntluong95 avatar May 18 '25 07:05 ntluong95

Thank you for opening this issue. I can reproduce this locally so I'll send this to triage.

Note for reproducing: The timeout occurs when the render resolution reaches a point of taking too long. RStudio took just over 10s at a roughly 500x500 resolution. In Positron, it timed out at 300x300 but worked at 200x200.

timtmok avatar May 21 '25 15:05 timtmok

I can look at this along with the plot timeout issue already on my backlog (https://github.com/posit-dev/positron/issues/5954).

jmcphers avatar May 22 '25 22:05 jmcphers

This isn't related to the plot timeout but seems to be an issue in Ark. In particular, Ark is sending the Idle status after processing the render request, but not actually delivering the render result until about 3s later (when it is discarded b/c we are no longer listening for it).

https://github.com/posit-dev/positron/blob/99c441cee05d7f3613435ae5d81537352c550f45/src/vs/workbench/api/browser/positron/mainThreadLanguageRuntime.ts#L1130-L1135

Some options:

  • extend the timeout (empirically 2s does not seem to be enough for some plots)
  • update ark so that it doesn't return the Idle status until after it has delivered the render result
  • eliminate the timeout entirely (just wait for a result until we get one or the RPC itself times out)
  • run away from home and live in the woods

jmcphers avatar May 28 '25 18:05 jmcphers

I think the message ordering is due to our handlers running in other threads in a non blocking way, which releases the Shell socket too early (and causes other potential issues such as concurrent R evals): https://github.com/posit-dev/ark/issues/689

lionel- avatar Jun 02 '25 16:06 lionel-