Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with saveWidget Function #488

Open
Billyjac2002 opened this issue Jul 22, 2024 · 1 comment
Open

Issue with saveWidget Function #488

Billyjac2002 opened this issue Jul 22, 2024 · 1 comment

Comments

@Billyjac2002
Copy link

I am encountering an error when trying to save a widget using the saveWidget function from the htmlwidgets package. The error message is: Error in .getNamespace(pkg) :
invalid type/length (symbol/0) in vector allocation

This error occurs even with minimal HTML content and different widgets.

Reproducible Example

# Load required libraries
library(leaflet)
library(htmltools)
library(htmlwidgets)

# Create a simple map
map <- leaflet() %>%
  addProviderTiles(providers$OpenStreetMap.Mapnik) %>%
  addMarkers(lng = 174.768, lat = -36.852, popup = "The birthplace of R")

# Minimal HTML content
minimal_html <- tags$p("Test paragraph")

# Test saving with minimal HTML content
html_file_minimal <- "test_route_assessment_map_minimal.html"
saveWidget(
  tagList(minimal_html, map), 
  html_file_minimal, 
  selfcontained = TRUE
)

**Steps Taken**

- Reinstalled all necessary packages.
- Tested with minimal HTML content.
- Tried different CRAN mirrors.
- Checked for package updates.
- Ran the code on a fresh R installation.
- Tested on a different machine/environment.
- Environment
- R version: 4.4.1
- Operating System: Windows 11 x64 (build 22631)

**Packages:**

- leaflet: 2.2.2
- htmltools: 0.5.8.1
- htmlwidgets: 1.6.4
@cpsievert
Copy link
Collaborator

cpsievert commented Jul 23, 2024

Is this a new problem (i.e., have you successfully used saveWidget() on a tagList() before)?

It would be great if saveWidget() just worked with shiny.tag or shiny.tag.list objects, but I believe it's currently limited to htmlwidget objects.

That said, you can save the tagList() to html with htmltools::save_html() (which doesn't have selfcontained = TRUE, but that's another known issue):

htmltools::save_html(
    tagList(minimal_html, map), 
    html_file_minimal,
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants