Output and render functions for using network() within Shiny applications
and interactive R Markdown / Quarto documents.
Usage
networkOutput(output_id, width = "100%", height = "480px")
renderNetwork(expr, env = parent.frame(), quoted = FALSE)Arguments
- output_id
Output variable to read from.
- width, height
Element size, passed to
htmlwidgets::shinyWidgetOutput().- expr
An expression that generates a
network()widget.- env
The environment in which to evaluate
expr.- quoted
Is
expralready quoted? Defaults toFALSE.
Value
networkOutput() returns a Shiny output UI element;
renderNetwork() returns a Shiny render function.
Details
In a Shiny app, clicking a node pushes its id (a character scalar, not a
row index) to input$<output_id>_selected, so networkOutput("graph")
populates input$graph_selected. It is NULL until the first click.
Examples
if (interactive() && requireNamespace("shiny", quietly = TRUE)) {
ui <- fluidPage(networkOutput("net"))
server <- function(input, output) {
output$net <- renderNetwork({
network(
nodes = data.frame(id = c("A", "B", "C")),
edges = data.frame(source = c("A", "B"), target = c("B", "C"))
)
})
}
shinyApp(ui, server)
}