为什么那个Trelliscope查看器显示空面板,没有图像?

问题描述

我在 Pokemon 上有以下数据框“p”。

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

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

我正在创建一个面板列,然后应用 Trelliscope 以访问和查看来自网络的 pokemon 图像(对应于数据框的“url_image”)。虽然它按预期生成一个 18 页的查看器,覆盖了 801 个面板,但所有面板都是空的,我看不到图像。

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

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

我已将所有 801 图像下载到本地文件夹“pokemon_local”,并尝试使用以下代码在Trelliscope 中查看它们。不幸的是,虽然Trelliscope 查看器正在生成,但面板还是空的。

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,path=path)

有人可以帮忙解释和解决吗?

解决方法

Pokemon 数据集为 available online,其中 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")))

只需转到侧边栏中的 Sort 选项卡并选择要排序的变量:Pokemons 出现 ;-)

enter image description here

trelliscope Issues 似乎自 2017 年以来一直处于搁置状态,这或许可以解释为什么这种意外行为没有得到纠正。

,

经过多次反复试验,并根据@Waldi 的回答中提供的提示,我发现我需要添加带有“pokemon”和“pokdex”元素标签列表的“state”变量。如果我们省略其中任何一个,它就不起作用。我不知道为什么?顺便说一句,我尝试使用“gapminder”数据集(与“pokemon dataset”不同,与图像无关)的其他几个示例,我们不需要创建“state”变量。

因此,如果我们使用以下代码更改问题中的 trelliscope() 函数代码,这两个选项都将起作用。

  1. 直接从网址访问和查看图像

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

  2. 访问和查看存储在本地磁盘上的图像

    trelliscope(p,"pokedex")),path=path)