Why is that Trelliscope viewer showing empty panels, no images?

241 views Asked by At

I have the below data frame "p" on Pokemon.

library("dplyr")
library("trelliscopejs")

glimpse(p)
Rows: 801
Columns: 5
$ pokemon       <chr> "bulbasaur", "ivysaur", "venusaur~
$ type_1        <chr> "grass", "grass", "grass", "grass~
$ attack        <int> 49, 62, 82, 100, 52, 64, 84, 130,~
$ generation_id <chr> "1", "1", "1", NA, "1", "1", "1",~
$ url_image     <chr> "http://assets.pokemon.com/assets~

I am creating a panel column and then applying Trelliscope in order to access and view the pokemon images from the web (corresponding to the "url_image" of the dataframe). Though it is generating a viewer with 18 pages covering 801 panels as expected, all the panels are empty and I cannot see the images.

p <- p %>%  mutate(panel = img_panel(url_image), pokemon = cog(val = pokemon, default_label = TRUE))

trelliscope(p, name = "pokemon", ncol=6, nrow=3)

I have downloaded all the 801 images to a local folder "pokemon_local" and tried to view them in Trelliscope using the below code. Unfortunately, again though the Trelliscope viewer is getting generated, the panels are empty.

path <- file.path("D:/xyz/pokemon_local")
dir.create(path)

for (url in p$url_image)
  download.file(url, destfile=file.path(path,basename(url)), quiet=TRUE, mode="wb")

p$image <- basename(p$url_image)
p<- mutate(p, panel=img_panel_local(image))

trelliscope(p, name="pokemon", nrow=3, ncol=6, path=path)

Can someone help with an explanation and solution?

2

There are 2 answers

0
Srinivas On BEST ANSWER

After several trial and error attempts, and based on the hint provided in @Waldi 's answer, I have discovered that I need to add "state" variable with a list of labels of "pokemon" and "pokdex" elements. If we omit either of them, it does not work. I don't know why? By the way, several other examples I tried with "gapminder" dataset (which is, unlike "pokemon dataset", not about images), we do not need to create "state" variable.

So if we change the trelliscope() function code in the question with the below code, both the options, will work.

  1. accessing and viewing images from web url directly

    trelliscope(p, name="pokemon", nrow=3, ncol=6, state = list(labels = c("pokemon", "pokedex")))

  2. accessing and viewing images stored on the local disk

    trelliscope(p, name="pokemon", nrow=3, ncol=6, state = list(labels = c("pokemon", "pokedex")), path=path)

0
Waldi On

Pokemon dataset is available online, which facilitates testing :

library(dplyr)
library(trelliscopejs)

pok <- read.csv("https://raw.githubusercontent.com/hafen/pokRdex/master/pokRdex_mod.csv") %>%
  mutate_at(vars(matches("_id$")), as.character)

pok %>%
  mutate(panel = img_panel(url_image)) %>%
  trelliscope("pokemon", nrow = 3, ncol = 6,
              state = list(labels = c("pokemon", "pokedex")))

Just go to Sort Tab in the sidebar and select a variable to sort on : the Pokemons appear ;-)

enter image description here

trelliscope Issues seem on hold since 2017, which might explain why this unexpected behaviour wasn't corrected.