15 R markdown
This chapter covers R markdown-specific functions of the twinetverse.
We’ve actually covered a few of those already, rtweet and graphTweets do not have functions specifically meant to be used in R markdown, all work just as well in a interactive and non-interactive environments. The dynamic nature of sigmajs, however, suggests the intriduction of additional functions.
# TK <- readRDS(file = "token.rds") tweets <- search_tweets("#rstats filter:mentions", n = 1000, token = TK, include_rts = FALSE)
some functions of the sigmajs package take a
delay argument, which, though can be used in any way or framework (shiny, R markdown, etc.), it is specifically designed with R markdown in mind. Take for instance the layout algorithm and button we used above; as you read this it is still running, which is draining for the browser and useless as the layout has stabilised. We could do the inverse of what we do above, of course, trigger the layout on page load and instead provide a button for the user to stop the layout. However, what would be ideal is for the layout to simply stop after a few seconds. Let’s implement the latter.
nodes <- sg_get_layout(nodes, edges) sigmajs() %>% sg_nodes(nodes, id, size, color, x, y) %>% sg_edges(edges, id, source, target) %>% sg_force_start() %>% sg_force_stop(10000)
We removed the button as we just trigger the layout algorithm when the page loads then we pass
sg_force_stop specifying that we want the force layout to stop after 10,000 milliseconds (10 seconds).