-
Notifications
You must be signed in to change notification settings - Fork 125
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
local images do not load #477
Comments
It seems that vis js accepts only URLs.
workaround: library(shiny)
library(visNetwork)
nodes <- data.frame(id = 1:4,
shape = c("image", "circularImage"),
image = paste0(1:4, ".png"),
label = "I'm an image")
edges <- data.frame(from = c(2,4,3,3), to = c(1,2,4,2))
visNetwork(nodes, edges, width = "100%") %>%
visNodes(shapeProperties = list(useBorderWithImage = TRUE)) %>%
visLayout(randomSeed = 2)
ui=fluidPage(
div(
# images hidden but reachable from URL
img(src='1.png'), # location: www/1.png
img(src='2.png'), # location: www/2.png
img(src='3.png'), # location: www/3.png
img(src='4.png'), # location: www/4.png
style="display: none;"
),
visNetworkOutput("netw")
)
server=function(input, output,session) {
output$netw <- renderVisNetwork(
visNetwork(nodes, edges, width = "100%") %>%
visNodes(shapeProperties = list(useBorderWithImage = TRUE)) %>%
visLayout(randomSeed = 2))
}
shinyApp(ui,server) |
ah, I missed that point in the documentation, thanks! I tried the suggested workaround but it does not work for my locally. Could it be I'm running Windows? |
I am on Linux but on Windows it's same in this case.
|
Thanks for the extended answer and help! I have the correct structure, but I still don't see icons. The issue now seems to be on my side, however, because changing to Do you plan to implement showing images from local paths without the shinyapp sidestep in the future? |
Yes, you have to manage that before. :)
I'm a simple user, not from datastorm-open/visNetwork's team nor visjs/vis-network's team. I like very much these packages, but don't expect too much about updates, because they have not changes since some years:
|
But I've found another answer from @Fideldue on Aug 21, 2018, without Shiny nor URLs :
Copy-paste + some adaptations: library(visNetwork)
myfulldir <- " my full path"
node <- NULL
nodes <- data.frame(id = 1:4,
shape = c("image", "circularImage"),
label = "I'm an image")
# Load in the dataframe the images, which are in myfulldir, in base64 encoded.
# The parameter is the id (1:4) to look for paste0(myfulldir,"/",x,".png")
# (don't forget to change "/" to "\" for Windows)
nodes$image=lapply(
nodes$id,
function(x) {
paste(
'data:image/png;base64',
RCurl::base64Encode(
readBin(
paste0(myfulldir,"/",x,".png"),
'raw',
as.integer(file.info(paste0(myfulldir,"/",x,".png"))$size)
),
"txt"
),
sep = ','
)
}
)
edges <- data.frame(from = c(2,4,3,3), to = c(1,2,4,2))
visNetwork(nodes, edges, width = "100%") %>%
visNodes(shapeProperties = list(useBorderWithImage = TRUE)) %>%
visLayout(randomSeed = 2)
|
Hi, I wanted to add local images to the network, but I can't figure out how to do so.
I managed to reproduce the example without an error,
But whenever I try using any other images, just blank nodes appear. For example, I downloaded the corresponding images to my working directory from https://github.com/datastorm-open/datastorm-open.github.io/tree/master/visNetwork/data/img/indonesia
such as
then
results in

without any errors or warnings
The text was updated successfully, but these errors were encountered: