# Basic configuration
config <- context_menu()
# Custom configuration with JavaScript functions
config <- context_menu(
key = "my-context-menu",
className = "my-context-menu",
trigger = "click",
offset = c(10, 10),
getItems = JS("(event) => {
const type = event.itemType;
const isNode = type === 'node';
return [
{ key: 'delete', text: 'Delete' },
{ key: 'edit', text: 'Edit' },
{ key: 'details', text: 'View Details', disabled: !isNode }
];
}"),
onClick = JS("(value, target, current) => {
if (value === 'delete') {
// do stuff
}")
)
if (interactive()) {
library(shiny)
library(g6R)
library(bslib)
nodes <- data.frame(id = c("node1", "node2"))
edges <- data.frame(source = "node1", target = "node2")
ui <- page_fluid(
g6_output("graph"),
verbatimTextOutput("contextmenu_info")
)
server <- function(input, output, session) {
output$graph <- render_g6({
g6(
nodes = nodes,
edges = edges
) |>
g6_layout() |>
g6_plugins(
context_menu()
)
})
output$contextmenu_info <- renderPrint({
input[["graph-contextmenu"]]
})
}
shinyApp(ui, server)
}
Run the code above in your browser using DataLab