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

slideView multiple points with Shiny #215

Open
maxlavoie opened this issue Mar 5, 2019 · 8 comments
Open

slideView multiple points with Shiny #215

maxlavoie opened this issue Mar 5, 2019 · 8 comments

Comments

@maxlavoie
Copy link

maxlavoie commented Mar 5, 2019

HI,
I recreated successfully your example with slideView found here https://www.rdocumentation.org/packages/mapview/versions/2.6.3/topics/slideView. My question is: Is it possible to use slideView on several points (i.e., one slideView per point). Like we do with images. I tried using multiple slideView or frameWidget but no luck. I like having two images per point. Sorry if this is the wrong place for asking. I could not find anything on that matter. love that package, thank you.

I tried something like that. The map render, but the slides don't show up

slide <- slideView(img2000, img2004)
slide2 <- slideView(img3000, img3004)
slides <- list(x, y)

coordinates(dat3) <- ~ GPSLongitude  + GPSLatitude #the data frame has 2 points
proj4string(dat3) <- "+init=epsg:4326"

m <- mapview(dat3, map.types = "Esri.WorldImagery", popup = lapply(slides, popupGraph))
@tim-salabim
Copy link
Member

Can you provide a reproducible example for me? I am struggling to understand what you are trying to do.

@maxlavoie
Copy link
Author

I am sorry for taking your time. By building the reproducible example, I did things differently, and I think I made it work. Here is what I was trying to do:

library(exifr)
library(dplyr)
library(leaflet)
library(readr) #for the updated version of read.csv
library(stringr) #for wrangling strings
library(RColorBrewer)
library(mapview)
library(raster)
library(OpenImageR)
library(magick)
library(jpeg)

data(poppendorf)
stck1 <- subset(poppendorf, c(3, 4, 5))
stck2 <- subset(poppendorf, c(2, 3, 4))
slideView(stck1, stck2)

slide <- slideView(stck1, stck2)

web_img2000 <- "http://cdn.newsapi.com.au/image/v1/68565a36c0fccb1bc43c09d96e8fb029"

jpg2000 <- readJPEG(readBin(web_img2000, "raw", 1e6))

rst_blue2000 <- raster(jpg2000[, , 1])
rst_green2000 <- raster(jpg2000[, , 2])
rst_red2000 <- raster(jpg2000[, , 3])

img2000 <- brick(rst_red2000, rst_green2000, rst_blue2000)

web_img2013 <- "http://cdn.newsapi.com.au/image/v1/5707499d769db4b8ec76e8df61933f2a"

jpg2013 <- readJPEG(readBin(web_img2013, "raw", 1e6))

rst_blue2013 <- raster(jpg2013[, , 1])
rst_green2013 <- raster(jpg2013[, , 2])
rst_red2013 <- raster(jpg2013[, , 3])

img2013 <- brick(rst_red2013, rst_green2013, rst_blue2013)

slide2 <- slideView(img2000, img2013)
slides <- list(slide, slide2)

dat3 <- data.frame(GPSLongitude = c(-78.653, -79.987), GPSLatitude = c(48.98, 46.98))

coordinates(dat3) <- ~ GPSLongitude + GPSLatitude
proj4string(dat3) <- "+init=epsg:4326"

mapview(dat3, map.types = "Esri.WorldImagery", popup = popupGraph(slides, type = "html"))

@tim-salabim
Copy link
Member

cool, yes that seems to work!

@maxlavoie
Copy link
Author

maxlavoie commented Mar 6, 2019

A quick question. In a shiny app (or flexdashboard), where should I put the images for the slideview? I tried inside the main app folder or in a www folder but the images are not displayed ("Not found" is written in the popup). Or any idea why the images are not displayed (the map and the points are there) in a shiny app. Ultimately, it does not matter if it's Shiny or Rmarkdown I just want to be able to share this map. Any suggestions? thanks!

@tim-salabim
Copy link
Member

Yeah this is a reoccuring issue. Outside of shiny they need to be one level higher than the index.html. I assume that this would also be the case for a shiny app but I have never tried it.

@maxlavoie
Copy link
Author

Here what I have done. server.R file inside the app folder (App > server.R). And the index.html (App > www > index.html) file is located in a www folder. And the images are in the app folder. Still, nothing showing up in the popup. When you say it is a reoccurring issue, do you have other examples where I could look into? Alternatively, I could use the same thing you used for your post (https://environmentalinformatics-marburg.github.io/mapview/popups/html/popups.html#). As long as I can share it. I would really like to make it work. It's a neat feature!

@tim-salabim
Copy link
Member

Again, a reproducible shiny app would be helpful.

@maxlavoie
Copy link
Author

OK, here is one:

library(exifr)
library(dplyr)
library(leaflet)
library(readr) #for the updated version of read.csv
library(stringr) #for wrangling strings
library(RColorBrewer)
library(mapview)
library(raster)
library(OpenImageR)
library(magick)
library(jpeg)

data(poppendorf)
stck1 <- subset(poppendorf, c(3, 4, 5))
stck2 <- subset(poppendorf, c(2, 3, 4))
slideView(stck1, stck2)

slide <- slideView(stck1, stck2)

web_img2000 <- "http://cdn.newsapi.com.au/image/v1/68565a36c0fccb1bc43c09d96e8fb029"

jpg2000 <- readJPEG(readBin(web_img2000, "raw", 1e6))

rst_blue2000 <- raster(jpg2000[, , 1])
rst_green2000 <- raster(jpg2000[, , 2])
rst_red2000 <- raster(jpg2000[, , 3])

img2000 <- brick(rst_red2000, rst_green2000, rst_blue2000)

web_img2013 <- "http://cdn.newsapi.com.au/image/v1/5707499d769db4b8ec76e8df61933f2a"

jpg2013 <- readJPEG(readBin(web_img2013, "raw", 1e6))

rst_blue2013 <- raster(jpg2013[, , 1])
rst_green2013 <- raster(jpg2013[, , 2])
rst_red2013 <- raster(jpg2013[, , 3])

img2013 <- brick(rst_red2013, rst_green2013, rst_blue2013)

slide2 <- slideView(img2000, img2013)
slides <- list(slide, slide2)

dat3 <- data.frame(GPSLongitude = c(-78.653, -79.987, -80), GPSLatitude = c(48.98, 46.98, 50))

coordinates(dat3) <- ~ GPSLongitude + GPSLatitude
proj4string(dat3) <- "+init=epsg:4326"

ui = fluidPage(

mapviewOutput("mymap")

)

server <- function(input, output, session){

output$mymap <- renderMapview({

mapview(dat3, map.types = "Esri.WorldImagery", popup = popupGraph(slides, type = "html"))

})

}

shinyApp(ui, server)

@maxlavoie maxlavoie reopened this Mar 14, 2019
@maxlavoie maxlavoie changed the title slideView multiple points slideView multiple points with Shiny Mar 14, 2019
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