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

Strange behavior of slideView() within rmarkdown #5

Open
aloboa opened this issue Dec 29, 2024 · 13 comments
Open

Strange behavior of slideView() within rmarkdown #5

aloboa opened this issue Dec 29, 2024 · 13 comments

Comments

@aloboa
Copy link

aloboa commented Dec 29, 2024

If we write the code of the example in the doc ?slideView within a Rmarkdown notebook
https://www.dropbox.com/scl/fi/xgdo0aouymnmscecqsa82/test_slideView_nb.Rmd?rlkey=sbfh741vpsewk4cxwc0yqmlv9&dl=0

We get an HTML with:

  • Labels bar at the top of the page
  • Floating graphic window

https://diapiro.geo3bcn.csic.es/alobo/blog/test_slideView_nb.nb.html

Also, the size of the plot is different than in plotRGB(), which is inconvenient if we use tabs:
https://www.dropbox.com/scl/fi/5qme5pj4lzz73dglvg2sf/test_slideView_v2_nb.Rmd?rlkey=wqgkg5r9oivl6e5jd0po5cbe4&dl=0

https://diapiro.geo3bcn.csic.es/alobo/blog/test_slideView_v2_nb.nb.html

I observe that in your README.Rmd you actually show a gif:
![](man/figures/slideview.gif)
and not the actual result of
slideView(img2000, img2013, label1 = "before", label2 = "after")

Are you doing this precisely because of the problem I am notifying?
How are you creating the gif? Is there an option within slideView() to create it?

@tim-salabim
Copy link
Member

@aloboa should be fixed now. Can you please check with the latest version from here...

@aloboa
Copy link
Author

aloboa commented Jan 4, 2025

Yes, many thanks for the fast fix.
The sliding view does not open initially in the window that opens after knit,
image

but it does as soon as I hit esc or return.

Also, the HTML is right now:
https://diapiro.geo3bcn.csic.es/alobo/blog/test_slideView_v3_nb.html

I think the labels' visibility must be increased, perhaps in bold?
Also, could the display match the color management of plotRGB() for consistency?

Rmd:
https://www.dropbox.com/scl/fi/s76gxda5kys94ypdkskux/test_slideView_v3_nb.Rmd?rlkey=hhnpe9wm6zqhshjcb1qvwq8y1&dl=0

@tim-salabim
Copy link
Member

tim-salabim commented Jan 4, 2025

The sliding view does not open initially in the window that opens after knit,

It does in Firefox (but not in Chromium). However, if there is no tabset, it also renders fine in Chromium...
So this is an issue with the browser. I'll have a look if I can find something regarding this difference in behaviour between Firefox and Chrome/ium (and possibly other browsers).

I think the labels' visibility must be increased, perhaps in bold?

Yes, I'll open another issue regarding this. This is controlled via CSS, so should be easy to implement.

Also, could the display match the color management of plotRGB() for consistency?

Also, another issue. I'll look into this when I consolidate the methods (raster to terra internally).

@aloboa
Copy link
Author

aloboa commented Jan 10, 2025

Using the last version (slideview_0.2.0.9000),
I have found that the rendered figure ignores the fig.align="center" option in the chunk:

https://diapiro.geo3bcn.csic.es/alobo/blog/test_slideView_v4.html

"```{r message=FALSE, warning=FALSE, fig.width=2, fig.height=4, fig.cap="Mar de Aral", fig.align="center"}
web_img2000 <- "http://cdn.newsapi.com.au/image/v1/68565a36c0fccb1bc43c09d96e8fb029"
img2000 <- rast(readJPEG(readBin(web_img2000, "raw", 1e6)))
web_img2013 <- "http://cdn.newsapi.com.au/image/v1/5707499d769db4b8ec76e8df61933f2a"
img2013 <- rast(readJPEG(readBin(web_img2013, "raw", 1e6)))
slideView(img2000, img2013, label1 = "before", label2 = "after", r=1, g=2, b=3)
"```

https://www.dropbox.com/scl/fi/f927u58m4eqn2m4tt7bjp/test_slideView_v4.Rmd?rlkey=6yejh09ehv52hqhvltk5n92hl&dl=0

@tim-salabim
Copy link
Member

Just to make sure it's still an issue, can you try with the latest version (0.2.0.9004)?

@aloboa
Copy link
Author

aloboa commented Jan 14, 2025

Yes, identical html with the same Rmd and:

> library(jpeg)
> library(terra)
> library(slideview)
> sessionInfo()
R version 4.4.2 (2024-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Pop!_OS 22.04 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=es_ES.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=es_ES.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=es_ES.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=es_ES.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Madrid
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] slideview_0.2.0.9004 terra_1.8-11         jpeg_0.1-10         

loaded via a namespace (and not attached):
 [1] digest_0.6.37     codetools_0.2-19  fastmap_1.2.0     xfun_0.50         lattice_0.22-5    raster_3.6-30     knitr_1.49        htmltools_0.5.8.1 rmarkdown_2.29   
[10] cli_3.6.3         viridisLite_0.4.2 grid_4.4.2        compiler_4.4.2    rstudioapi_0.15.0 tools_4.4.2       sp_2.1-4          evaluate_1.0.3    Rcpp_1.0.14      
[19] yaml_2.3.10       rlang_1.1.4   

@tim-salabim
Copy link
Member

Did it work before to set fig.align?

@aloboa
Copy link
Author

aloboa commented Jan 14, 2025

Do not know, I had not used fig.align with this function before. I reported as soon as I detected the issue.
Note that the problem is just that the figure is not centered despite fig.aling in the chunk options.

@tim-salabim
Copy link
Member

Does it work for e.g. a leaflet map?

@aloboa
Copy link
Author

aloboa commented Jan 14, 2025

I have not tried and my leaflet abilities are rusty. I should be able to try in a few days, I have to take some days off
because of health reasons starting tomorrow.

@tim-salabim
Copy link
Member

Oh, I wish a good recovery. Maybe I will be able to try. Will post here if I do

@aloboa
Copy link
Author

aloboa commented Jan 16, 2025

It seems I can do some work...
I have tried this, but it does not work:

---
title: "Untitled"
author: "A. Lobo"
date: "2025-01-16"
output:
  flexdashboard::flex_dashboard:
    theme: 
      version: 4
      bootswatch: spacelab
    orientation: rows
    navbar:
      - { title: "[email protected]", align: right }
---

```{r}
library(leaflet)
library(leafem)
library(slideview)
library(terra)
library(RStoolbox) #for the examples

lsat <- project(lsat, "EPSG:4326")
uc <- unsuperClass(lsat, nClasses = 3)$map
uc <- project(uc, "EPSG:4326")
xy <- geom(centroids(as.polygons(ext(uc))))
#slideView(lsat, uc, label1 = "image", label2 = "classif")


m = leaflet() %>% setView(lng = xy[3], lat = xy[4], zoom = 12) %>% addTiles() 
m %>% addRasterImage(slideView(lsat, uc, label1 = "image", label2 = "classif"))
Show in New Window
Error in addRasterImage(., slideView(lsat, uc, label1 = "image", label2 = "classif")) : 
  Don't know how to get path data from object of class slideView

@aloboa
Copy link
Author

aloboa commented Jan 28, 2025

Following tje documentation and using the following chunk in the Rmd file:

slideView(
  img2000,
  img2013,
  label1 = "before", label2 = "after", r=1, g=2, b=3,
  sliderInfoCSS = list(
    "background-color" = "#00ffff"
    , "color" = "#ff00ff"
    , opacity = 0.8
    , "font-size" = "30px"
    , "font-family" = "courier"
  )
)

I get:

Image

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