I am trying to update a diagram in R Studio viewer at each step of a for loop.
At the end of the loop I would like to obtain this:
But I obtain this:
The code for the above is like this:
library(tidyverse)
library(DiagrammeR)
a_graph <-
create_graph() %>%
add_node(label = 'Start', type = 'actif', node_aes = node_aes(fillcolor = "orange",shape = "rectangle"
) )
a_graph %>% render_graph()
update_my_graph <- function(label, label_from){
from_id <- which( (a_graph %>% get_node_df())$label==label_from )
a_graph <<- a_graph %>%
select_nodes(
conditions =
type == 'actif') %>%
set_node_attrs_ws(
node_attr = fillcolor,
value = "blue") %>%
clear_selection() %>%
add_node(label = label, from = from_id, type = 'actif', node_aes = node_aes(fillcolor = "orange",shape = "rectangle",fixedsize = FALSE))
a_graph %>% render_graph(layout = "tree")
}
for(i in 1:5) update_my_graph(i,'Start')
R version 3.4.1 (2017-06-30) -- "Single Candle" tidyverse 1.2.1 DiagrammeR 1.0.0 RStudio 1.1.383