Description Usage Arguments Details Value See Also Examples
React to user-interaction events on the server-side in Shiny.
1 | sg_events(sg, events)
|
sg |
An object of class |
events |
A vector or list of valid events (see section below). |
The parameter events
is either a simple vector with the valid names of
events (see below), e.g. c("clickNode", "overNode")
.
An alternative possibility for events
is to pass a list of named lists,
where each named list has an entry "event" with the valid event name and
optionally an entry "priority" specifying the priority of the event, e.g.
list(list(event = "clickNode"), list(event = "overNode", priority = "event"))
.
A priority of mode "event" means that the event is dispatched every time, not only when its returned value changes. Shiny's default priority "immediate" (also used when no priority is specified) would only dispatch when e.g. the clicked or hovered node is different from before. See https://shiny.rstudio.com/articles/communicating-with-js.html for more information.
Events:
Valid event names to pass to events
.
clickNode
clickNodes
clickEdge
clickEdges
clickStage
doubleClickStage
rightClickStage
doubleClickNode
doubleClickNodes
doubleClickEdge
doubleClickEdges
rightClickNode
rightClickNodes
rightClickEdge
rightClickEdges
overNode
overNodes
overEdge
overEdges
outNode
outNodes
outEdge
outEdges
The corresponding Shiny events to observe have the same name, only written in
lowercase, words separated with underscores, and prefixed with the
outputId
of the sigmajsOutput()
. For example, when outputId
is "graph": the clickNode
event in Shiny becomes input$graph_click_node
,
the overNode
event in Shiny becomes input$graph_over_node
, and
so on.
An object of class htmlwidget
which renders the visualisation on print.
official sigmajs documentation, Shiny article about communicating with JavaScript.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | library(shiny)
nodes <- sg_make_nodes()
edges <- sg_make_edges(nodes)
ui <- fluidPage(
sigmajsOutput("graph"),
p("Click on a node"),
verbatimTextOutput("clicked")
)
server <- function(input, output){
output$graph <- renderSigmajs({
sigmajs() %>%
sg_nodes(nodes, id, size, color) %>%
sg_edges(edges, id, source, target) %>%
sg_events("clickNode")
})
# capture node clicked (only fires when a new node is clicked)
output$clicked <- renderPrint({
c(list(clickTime = Sys.time()), input$graph_click_node)
})
}
## Not run: shinyApp(ui, server)
server2 <- function(input, output){
output$graph <- renderSigmajs({
sigmajs() %>%
sg_nodes(nodes, id, size, color) %>%
sg_edges(edges, id, source, target) %>%
sg_events(list(list(event = "clickNode", priority = "event")))
})
# capture node clicked (every time, also when clicking the same node again)
output$clicked <- renderPrint({
c(list(clickTime = Sys.time()), input$graph_click_node)
})
}
## Not run: shinyApp(ui, server2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.