Closed Pablo-Sar closed 3 weeks ago
I pasted the screenshot in R 4.3.3 since I change the version to plot the diagram.
In R 4.3.3 works just fine.
can you copy-paste the reproducible code here?
can you copy-paste the reproducible code here?
Sorry I put another example in my description.
# **Load package**
library(networkD3)
# **Load energy projection data**
URL <- "https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json"
Energy <- jsonlite::fromJSON(URL)
# **Now we have 2 data frames: a 'links' data frame with 3 columns (from, to, value), and a 'nodes' data frame that gives the name of each node.**
head( Energy$links )
head( Energy$nodes )
# **Thus we can plot it**
sankeyNetwork(Links = Energy$links,
Nodes = Energy$nodes,
Source = "source",
Target = "target",
Value = "value",
NodeID = "name",
units = "TWh",
fontSize = 12,
nodeWidth = 30)
I have the same issue (no sankeyNetwork displayed in R4.4.0). I can save the network though - just not view it in RStudio (2024.04.2+764 "Chocolate Cosmos")
library(networkD3)
URL <- "https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json"
Energy <- jsonlite::fromJSON(URL)
sn<-sankeyNetwork(Links = Energy$links,
Nodes = Energy$nodes,
Source = "source",
Target = "target",
Value = "value",
NodeID = "name",
units = "TWh",
fontSize = 12,
nodeWidth = 30)
saveNetwork(sn, "sn.html")
library(webshot)
webshot("sn.html","sn.png", vwidth = 1000, vheight = 900)
can you copy-paste the reproducible code here?
Sorry I put another example in my description.
Load package library(networkD3)
Load energy projection data URL <- "https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json" Energy <- jsonlite::fromJSON(URL)
Now we have 2 data frames: a 'links' data frame with 3 columns (from, to, value), and a 'nodes' data frame that gives the name of each node. head( Energy$links ) head( Energy$nodes )
Thus we can plot it sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source", Target = "target", Value = "value", NodeID = "name", units = "TWh", fontSize = 12, nodeWidth = 30)
This works as expected for me. Maybe some combination of networkD3 version, R version, OS type, OS version, etc. is causing a conflict? Hard to say without being able to reproduce.
library(networkD3)
# Load energy projection data
URL <- "https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json"
Energy <- jsonlite::fromJSON(URL)
# Now we have 2 data frames: a 'links' data frame with 3 columns (from, to,
# value), and a 'nodes' data frame that gives the name of each node.
head( Energy$links )
#> source target value
#> 1 0 1 124.729
#> 2 1 2 0.597
#> 3 1 3 26.862
#> 4 1 4 280.322
#> 5 1 5 81.144
#> 6 6 2 35.000
head( Energy$nodes )
#> name
#> 1 Agricultural 'waste'
#> 2 Bio-conversion
#> 3 Liquid
#> 4 Losses
#> 5 Solid
#> 6 Gas
# Thus we can plot it
sankeyNetwork(Links = Energy$links,
Nodes = Energy$nodes,
Source = "source",
Target = "target",
Value = "value",
NodeID = "name",
units = "TWh",
fontSize = 12,
nodeWidth = 30)
sessionInfo()
#> R version 4.4.1 (2024-06-14)
#> Platform: aarch64-apple-darwin20
#> Running under: macOS 15.0
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0
#>
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#>
#> time zone: Europe/Berlin
#> tzcode source: internal
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] networkD3_0.4
#>
#> loaded via a namespace (and not attached):
#> [1] cli_3.6.3 knitr_1.48 rlang_1.1.4 xfun_0.47
#> [5] processx_3.8.4 promises_1.3.0 jsonlite_1.8.8 glue_1.7.0
#> [9] htmltools_0.5.8.1 ps_1.8.0 chromote_0.3.1 rmarkdown_2.28
#> [13] evaluate_0.24.0 fastmap_1.2.0 yaml_2.3.10 lifecycle_1.0.4
#> [17] compiler_4.4.1 igraph_2.0.3 fs_1.6.4 websocket_1.4.2
#> [21] htmlwidgets_1.6.4 Rcpp_1.0.13 pkgconfig_2.0.3 rstudioapi_0.16.0
#> [25] later_1.3.2 webshot2_0.1.1 digest_0.6.37 R6_2.5.1
#> [29] reprex_2.1.1 magrittr_2.0.3 webshot_0.5.5 tools_4.4.1
#> [33] withr_3.0.1
I have the same issue (no sankeyNetwork displayed in R4.4.0). I can save the network though - just not view it in RStudio (2024.04.2+764 "Chocolate Cosmos")
URL <- "https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json" Energy <- jsonlite::fromJSON(URL) sn<-sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source", Target = "target", Value = "value", NodeID = "name", units = "TWh", fontSize = 12, nodeWidth = 30) saveNetwork(sn, "sn.html") library(webshot) webshot("sn.html","sn.png", vwidth = 1000, vheight = 900) '''
This also works as expected for me on R v4.4.1. Any idea what about your specific environment might be different than usual?
library(networkD3)
URL <- "https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json"
Energy <- jsonlite::fromJSON(URL)
sn<-sankeyNetwork(Links = Energy$links,
Nodes = Energy$nodes,
Source = "source",
Target = "target",
Value = "value",
NodeID = "name",
units = "TWh",
fontSize = 12,
nodeWidth = 30)
sn
sessionInfo()
#> R version 4.4.1 (2024-06-14)
#> Platform: aarch64-apple-darwin20
#> Running under: macOS 15.0
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0
#>
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#>
#> time zone: Europe/Berlin
#> tzcode source: internal
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] networkD3_0.4
#>
#> loaded via a namespace (and not attached):
#> [1] cli_3.6.3 knitr_1.48 rlang_1.1.4 xfun_0.47
#> [5] processx_3.8.4 promises_1.3.0 jsonlite_1.8.8 glue_1.7.0
#> [9] htmltools_0.5.8.1 ps_1.8.0 chromote_0.3.1 rmarkdown_2.28
#> [13] evaluate_0.24.0 fastmap_1.2.0 yaml_2.3.10 lifecycle_1.0.4
#> [17] compiler_4.4.1 igraph_2.0.3 fs_1.6.4 websocket_1.4.2
#> [21] htmlwidgets_1.6.4 Rcpp_1.0.13 pkgconfig_2.0.3 rstudioapi_0.16.0
#> [25] later_1.3.2 webshot2_0.1.1 digest_0.6.37 R6_2.5.1
#> [29] reprex_2.1.1 magrittr_2.0.3 webshot_0.5.5 tools_4.4.1
#> [33] withr_3.0.1
I guess I must have not updated something - here is my session info:
> library(networkD3)
> URL <- "https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json"
> Energy <- jsonlite::fromJSON(URL)
> sn<-sankeyNetwork(Links = Energy$links,
+ Nodes = Energy$nodes,
+ Source = "source",
+ Target = "target",
+ Value = "value",
+ NodeID = "name",
+ units = "TWh",
+ fontSize = 12,
+ nodeWidth = 30)
> sn
> sessionInfo()
R version 4.4.0 (2024-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
[1] LC_COLLATE=nb-NO.utf-8 LC_CTYPE=nb-NO.utf-8 LC_MONETARY=nb-NO.utf-8
[4] LC_NUMERIC=C LC_TIME=nb-NO.utf-8
time zone: Europe/Oslo
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] networkD3_0.4.9000
loaded via a namespace (and not attached):
[1] vctrs_0.6.5 data.tree_1.1.0 cli_3.6.2 knitr_1.48 rlang_1.1.3
[6] xfun_0.47 stringi_1.8.4 processx_3.8.2 purrr_1.0.2 styler_1.10.2
[11] jsonlite_1.8.8 glue_1.7.0 clipr_0.8.0 htmltools_0.5.8.1 ps_1.7.5
[16] fansi_1.0.6 rmarkdown_2.28 R.cache_0.16.0 evaluate_0.24.0 tibble_3.2.1
[21] fastmap_1.2.0 yaml_2.3.10 lifecycle_1.0.4 compiler_4.4.0 igraph_2.0.3
[26] fs_1.6.4 htmlwidgets_1.6.4 pkgconfig_2.0.3 rstudioapi_0.15.0 R.oo_1.26.0
[31] R.utils_2.12.3 digest_0.6.31 R6_2.5.1 reprex_2.0.2 utf8_1.2.4
[36] pillar_1.9.0 callr_3.7.3 magrittr_2.0.3 R.methodsS3_1.8.2 tools_4.4.0
[41] withr_3.0.1
I would guess it's a problem with RStudio, since the export is working and the viewer in RStudio is a completely RStudio specific situation. Maybe raise it on their GitHub repo? Do other htmlwidgets (or anything) display properly in your RStudio viewer?
I have the same problem - I updated my RStudio version yesterday.
Running the same example from the sankeyNetwork help file using R 4.4.0, the resulting output does not display in the viewer or in the browser if I try to view it in a new window.
The error message in the browser starts with a message that "this page isn't working. localhost did not send any data", before switching to "This site can’t be reached. The web page at http://localhost:blah/blah/index.html might be temporarily down or it may have moved permanently to a new web address. ERR_SOCKET_NOT_CONNECTED
I initially thought it might be an issue with the new version of RStudio. But when I use it and switch back to my previous R install of 4.3.2, the network displays correctly both in the viewer and in external browser window.
RStudio 2024.09.0+375 "Cranberry Hibiscus" Release (c8fc7aee6dc218d5687553f9041c6b1e5ea268ff, 2024-09-16) for windows Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) RStudio/2024.09.0+375 Chrome/124.0.6367.243 Electron/30.4.0 Safari/537.36, Quarto 1.5.57
R Session Info
R 4.4.0
R version 4.4.0 (2024-04-24 ucrt) Platform: x86_64-w64-mingw32/x64 Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.utf8 LC_CTYPE=English_United Kingdom.utf8
[3] LC_MONETARY=English_United Kingdom.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.utf8
time zone: Europe/London tzcode source: internal
attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages: [1] networkD3_0.4
loaded via a namespace (and not attached):
[1] htmlwidgets_1.6.4 compiler_4.4.0 magrittr_2.0.3 fastmap_1.2.0 cli_3.6.3
[6] htmltools_0.5.8.1 tools_4.4.0 igraph_2.1.1 rstudioapi_0.17.1 yaml_2.3.10
[11] jsonlite_1.8.9 digest_0.6.37 lifecycle_1.0.4 pkgconfig_2.0.3 rlang_1.1.4
R 4.3.2 (works as expected)
R version 4.3.2 (2023-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.utf8 LC_CTYPE=English_United Kingdom.utf8
[3] LC_MONETARY=English_United Kingdom.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.utf8
time zone: Europe/London tzcode source: internal
attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages: [1] networkD3_0.4
loaded via a namespace (and not attached):
[1] htmlwidgets_1.6.4 compiler_4.3.2 magrittr_2.0.3 fastmap_1.2.0 cli_3.6.3
[6] htmltools_0.5.8.1 tools_4.3.2 igraph_2.0.3 rstudioapi_0.16.0 yaml_2.3.10
[11] jsonlite_1.8.9 digest_0.6.37 lifecycle_1.0.4 pkgconfig_2.0.3 rlang_1.1.4
The error message in the browser starts with a message that "this page isn't working. localhost did not send any data", before switching to "This site can’t be reached. The web page at http://localhost:blah/blah/index.html might be temporarily down or it may have moved permanently to a new web address. ERR_SOCKET_NOT_CONNECTED
This is very, very likely to be something with RStudio (or whatever it uses to run a local server in the background). networkD3 (and not even htmlwidgets) does not have anything to do with running a local server that can/should be accessed at localhost.
have just checked on another Windows machine with R 4.4.1 and the same version of RStudio, everything works as expected, so possibly something related to 4.4.0 itself? It certainly doesn't appear to be an issue with this package.
R version 4.4.1 (2024-06-14 ucrt) Platform: x86_64-w64-mingw32/x64 Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.utf8 LC_CTYPE=English_United Kingdom.utf8
[3] LC_MONETARY=English_United Kingdom.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.utf8
time zone: Europe/London tzcode source: internal
attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages: [1] networkD3_0.4 devtools_2.4.5 usethis_3.0.0
loaded via a namespace (and not attached):
[1] jsonlite_1.8.8 miniUI_0.1.1.1 compiler_4.4.1 promises_1.3.0 Rcpp_1.0.13 stringr_1.5.1
[7] later_1.3.2 yaml_2.3.10 fastmap_1.2.0 mime_0.12 R6_2.5.1 igraph_2.1.1
[13] htmlwidgets_1.6.4 profvis_0.3.8 shiny_1.9.1 rlang_1.1.4 cachem_1.1.0 stringi_1.8.4
[19] httpuv_1.6.15 fs_1.6.4 pkgload_1.4.0 memoise_2.0.1 cli_3.6.3 magrittr_2.0.3
[25] digest_0.6.37 rstudioapi_0.16.0 xtable_1.8-4 remotes_2.5.0 lifecycle_1.0.4 vctrs_0.6.5
[31] glue_1.7.0 urlchecker_1.0.1 sessioninfo_1.2.2 pkgbuild_1.4.4 purrr_1.0.2 pkgconfig_2.0.3
[37] tools_4.4.1 ellipsis_0.3.2 htmltools_0.5.8.1
does the error you see really say
that seems ridiculous enough that the source of it shouldn't be too hard to find
no sorry, it was a longer, more sensible path to the page on localhost (not on that machine at the moment) but I didn't want to type the whole path out. The function works as expected in 4.3.2, and 4.4.1 using the same new version of RStudio, so I will upgrade my install to 4.4.1 on the other machine.
There is one thing in NEWS that might explain this:
The internal help server on Windows can again serve requests sent in quick succession, fixing a regression in R 4.4.0.
There is one thing in NEWS that might explain this:
The internal help server on Windows can again serve requests sent in quick succession, fixing a regression in R 4.4.0.
indeed... thank you! https://bugs.r-project.org/show_bug.cgi?id=18717 https://github.com/rstudio/rstudio/issues/14603
I followed the example in https://r-charts.com/flow/sankey-diagram-ggplot2/ to plot the sankey diagram but in the viewer just appeared in blank without any error in the console.