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

rmarkdown self_contained: false doesn't render image #30

Open
tim-salabim opened this issue Sep 8, 2020 · 0 comments
Open

rmarkdown self_contained: false doesn't render image #30

tim-salabim opened this issue Sep 8, 2020 · 0 comments

Comments

@tim-salabim
Copy link
Member

tim-salabim commented Sep 8, 2020

When opened in a browser the following .Rmd fails with

Fetch API cannot load file:///C:/Users/Tim/Desktop/test_georaster_files/stars-0.0.1/stars_layer.tif. URL scheme must be "http" or "https" for CORS request.
    ---
    title: "Some title"
    author: "Some author"
    date: "Some date"
    output: 
      html_document:
        self_contained: false
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    ```
    
    
    ```{r geotiff}
    library(stars)
    library(leaflet)
    library(leafem)
    
    tif = system.file("tif/L7_ETMs.tif", package = "stars")
    (x1 = read_stars(tif))
    strs = st_warp(x1, crs = 4326)
    fl = tempfile(fileext = ".tif")
    write_stars(strs, fl)
    pal = grDevices::colorRampPalette(hcl.colors(9, "viridis"))
    colops = colorOptions(
      palette = pal
      , domain = c(-1, 1)
      , na.color = "#bebebe"
      , breaks = NULL
    )
    
    ndvi = function(x) (x[4] - x[3]) / (x[4] + x[3])
    
    leaflet() %>%
      addTiles() %>%
      addGeotiff(
        file = fl
        , group = "stars"
        , resolution = 64
        , arith = ndvi
        , colorOptions = colops
      )
    ```

If self_contained: true it works as apparently all attachements are being included in the html document. This is fine for small images, but will fail miserably for even medium sized tif filesf I fear.

To get this to work we need the latest dev version of leafem:

remotes::install_github("r-spatial/leafem")

I assume that this isn't working because the .Rmd is not served via localhost. Not sure how to solve this...

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

1 participant