Skip to content

HOWTO receive event when node is selected #464

@kjeipta

Description

@kjeipta

#176 Shows how to retrieve the selected node after-the-fact with an additional button press. Can you please give an example of how to process the selection of a node by a user as an event using observeEvent where the event handler accesses the position information of the selected node?

There is code in the project I am working on that added a JavaScript select handler to propagate the selected data and edge information:

    output$network <- renderVisNetwork(
      {
        visNetwork(nodes, edges, height = "800px", width = "100%") %>%
   :
   :
          visEvents(select = glue::glue("function(data) {{
                                    Shiny.setInputValue('{NS(id)('current_nodes_selection')}', data.nodes);
                                    Shiny.setInputValue('{NS(id)('current_edges_selection')}', data.edges);
                                    ;}}"))

But this seems to break other functionality like the ability to get node positions while only returning the ID of the selected nodes. This no longer works with the JavaScript event hander in place:

visNetworkProxy("network") %>% visGetPositions()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions