htmlwidgets

Fixing the order of a Sankey flow graph in R / networkD3 package

家住魔仙堡 提交于 2019-12-19 09:32:10
问题 I would like to visualize a rank change (i.e. change of the relative order) of US states using a Sankey flow graph. I'm using the networkd3 package and came up with the following: library(dplyr) library(networkD3) df <- data_frame(origins=state.name[1:10], destinations=state.name[1:10]) lab <- c(df$origins, df$destinations) nodes <- data.frame(node=c(0:9), name=lab) links <- data.frame(source=c(0:9), target=c(10:19), value=rep(1,10)) sankeyNetwork(Links = links, Nodes = nodes, Source =

Fixing the order of a Sankey flow graph in R / networkD3 package

你离开我真会死。 提交于 2019-12-19 09:30:15
问题 I would like to visualize a rank change (i.e. change of the relative order) of US states using a Sankey flow graph. I'm using the networkd3 package and came up with the following: library(dplyr) library(networkD3) df <- data_frame(origins=state.name[1:10], destinations=state.name[1:10]) lab <- c(df$origins, df$destinations) nodes <- data.frame(node=c(0:9), name=lab) links <- data.frame(source=c(0:9), target=c(10:19), value=rep(1,10)) sankeyNetwork(Links = links, Nodes = nodes, Source =

How to color groups in networkD3's sankeyNetwork?

[亡魂溺海] 提交于 2019-12-19 03:56:39
问题 My nodes consists of names and groups yet I can't seem to implement distinct colors for groups in my sankey diagram. The colors are either all blue with defaults or all black using the code below. Here's the code I use: sankeyNetwork( Links = data$links, Nodes = data$nodes, Source= "source", Target = "target", Value = "weight", NodeID = "names", fontSize = 15, NodeGroup = "group" )) Here's the output I'm getting: 回答1: The NodeGroup vector in the Nodes data frame needs to be non-numeric. That

Sankey diagram in R

痴心易碎 提交于 2019-12-18 13:28:21
问题 Attempting to make a fairly generic Sankey diagram with the help of R's networkD3 package. Just for reference--here's the example from the package's manual library(networkD3) library(jsonlite) library(magrittr) energy <- "https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json" %>% fromJSON sankeyNetwork(Links = energy$links, Nodes = energy$nodes, Source = "source", Target = "target", Value = "value", NodeID = "name", units = "TWh", fontSize = 12, nodeWidth = 30) which

R Shiny includeHTML missing htmlWidgets in a reactive context

不羁岁月 提交于 2019-12-18 09:26:56
问题 UPDATE: I posted a related question here I need to include an html file in shiny using includeHTML. The file is generated by rmarkdown, and has a large number of htmlWidgets. Shiny is showing the html file, but the htmlWidgests are missing. The problem occurs only when includeHTML is in server.R, but works ok if includeHTLM is in ui.R. I need to update file.html so includeHTML must be used in a reactive context. The file.rmd is somthing like this --- title: "test" author: "me" date: '`r Sys

R Leaflet plot ship direction

萝らか妹 提交于 2019-12-18 09:17:30
问题 I have information on the location of vessels/ships and the course they are steering. I'd like to plot them on a leaflet map with a custom icon which looks like a ship. I found the "tags" icon from glyphicons to be most suitable. Here's some data to play with: dput(head(x)) structure(list(boatName = c("Conti Benguela", "Sunny Bay", "Sunny Horizon", "FMT URLA", "Qi Xiang 22", "STI Solidarity"), lat = c(37.115365, 38.4772017, 14.632, 56.80515, 51.31172, -2.2783283), lon = c(15.2682183, -8

R Leaflet plot ship direction

百般思念 提交于 2019-12-18 09:16:06
问题 I have information on the location of vessels/ships and the course they are steering. I'd like to plot them on a leaflet map with a custom icon which looks like a ship. I found the "tags" icon from glyphicons to be most suitable. Here's some data to play with: dput(head(x)) structure(list(boatName = c("Conti Benguela", "Sunny Bay", "Sunny Horizon", "FMT URLA", "Qi Xiang 22", "STI Solidarity"), lat = c(37.115365, 38.4772017, 14.632, 56.80515, 51.31172, -2.2783283), lon = c(15.2682183, -8

R networkD3 package: node coloring in simpleNetwork()

僤鯓⒐⒋嵵緔 提交于 2019-12-17 10:55:15
问题 The networkD3 package (see here and here) allows a user to create simple interactive networks: # Load package library(networkD3) # Create fake data src <- c("A", "A", "A", "A", "B", "B", "C", "C", "D") target <- c("B", "C", "D", "J", "E", "F", "G", "H", "I") networkData <- data.frame(src, target) # Plot simpleNetwork(networkData) Is there a way to specify that I want all elements in the src vector to be a certain color, while allowing all the elements in the target vector to be a different

Include sparkline htmlwidget in datatable cells in a Shiny app, without resorting to (much) JavaScript

狂风中的少年 提交于 2019-12-14 03:42:34
问题 I am using the sparkline package to produce bar charts to place into cells of a datatable in a Shiny app. I've managed to produce the desired output in a standalone datatable , but when I place it into the Shiny app it doesn't work. It may have something to do with how spk_add_deps() identifies the htmlwidgets. I've tried moving the spk_add_deps() function around quite a bit and passing it various identifiers, and nothing worked. I did find essentially the same question here Render datatable

Using Shiny actionButton() function in onRender() function of htmlWidgets

柔情痞子 提交于 2019-12-13 16:06:43
问题 I have a Shiny application in which a user can select black points in a Plotly scatterplot using the Plotly "box select" icon. The points the user selects will be highlighted in red. I have a MWE of this application below: library(plotly) library(htmlwidgets) library(shiny) ui <- shinyUI(fluidPage( plotlyOutput("myPlot") )) server <- shinyServer(function(input, output) { p <- ggplot(mtcars, aes(x = wt, y = mpg)) + xlim(10,40) +ylim(0,10) ggPS <- ggplotly(p) output$myPlot <- renderPlotly(ggPS