{"action":"created","issue":{"url":"https://api.github.com/repos/datastorm-open/visNetwork/issues/243","repository_url":"https://api.github.com/repos/datastorm-open/visNetwork","labels_url":"https://api.github.com/repos/datastorm-open/visNetwork/issues/243/labels{/name}","comments_url":"https://api.github.com/repos/datastorm-open/visNetwork/issues/243/comments","events_url":"https://api.github.com/repos/datastorm-open/visNetwork/issues/243/events","html_url":"https://github.com/datastorm-open/visNetwork/issues/243","id":308051813,"number":243,"title":"visNearestNodes and modules","user":{"login":"johndrummond","id":1420655,"avatar_url":"https://avatars2.githubusercontent.com/u/1420655?v=4","gravatar_id":"","url":"https://api.github.com/users/johndrummond","html_url":"https://github.com/johndrummond","followers_url":"https://api.github.com/users/johndrummond/followers","following_url":"https://api.github.com/users/johndrummond/following{/other_user}","gists_url":"https://api.github.com/users/johndrummond/gists{/gist_id}","starred_url":"https://api.github.com/users/johndrummond/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johndrummond/subscriptions","organizations_url":"https://api.github.com/users/johndrummond/orgs","repos_url":"https://api.github.com/users/johndrummond/repos","events_url":"https://api.github.com/users/johndrummond/events{/privacy}","received_events_url":"https://api.github.com/users/johndrummond/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-03-23T14:30:58Z","updated_at":"2018-03-26T15:49:22Z","closed_at":null,"author_association":"NONE","body":"in https://github.com/datastorm-open/visNetwork/issues/241\r\n@bthieurmel  kindly pointed out how to use namespaces with a module with an event, which is great.\r\nBut I find myself equally lost with modules, namespaces and visNearestNodes, regardless of where I try and add ns.\r\ne.g.  changing the line visNetworkProxy(\"network\")\r\nfor  visNetworkProxy(ns(\"network\")) doesn't work either\r\n\r\nI'm hoping this is obvious to someone, or there's a better way to do it.\r\n-----\r\nThank you.\r\n-----\r\n\r\nE.g. no module and working\r\n`require(visNetwork)\r\nrequire(shiny)\r\n\r\nnodes <- data.frame(id = 1:15, label = paste(\"Label\", 1:15),\r\n                    group = sample(LETTERS[1:3], 15, replace = TRUE))\r\n\r\nedges <- data.frame(from = trunc(runif(15)*(15-1))+1,\r\n                    to = trunc(runif(15)*(15-1))+1)\r\n\r\nserver <- function(input, output, session) {\r\n  output$network <- renderVisNetwork({\r\n    visNetwork(nodes, edges, \r\n               height = \"100%\", width = \"100%\",\r\n               main = \"\") %>%\r\n      visEvents(click = \"function(nodes){\r\n                Shiny.onInputChange('click', nodes.nodes[0]);\r\n                ;}\"\r\n      )\r\n})\r\n  \r\n  output$node_found <- renderText(input$click)\r\n  \r\n  output$shiny_return <- renderPrint({\r\n    visNetworkProxy(\"network\") %>%\r\n      visNearestNodes(target = input$click)\r\n  })\r\n  }\r\n\r\nui <- fluidPage(\r\n  visNetworkOutput(\"network\"), \r\n  verbatimTextOutput(\"node_found\"), \r\n  verbatimTextOutput(\"shiny_return\")  \r\n)\r\n\r\nshiny::shinyApp(ui = ui, server = server)`\r\n\r\nWith modules and not working for the nearest nodes (the found node does work as helped previously)\r\n\r\n`# install dev version\r\n#devtools::install_github(\"datastorm-open/visNetwork\")\r\n\r\nrequire(visNetwork)\r\nrequire(shiny)\r\n\r\nnodes <- data.frame(id = 1:15, label = paste(\"Label\", 1:15),\r\n                    group = sample(LETTERS[1:3], 15, replace = TRUE))\r\n\r\nedges <- data.frame(from = trunc(runif(15)*(15-1))+1,\r\n                    to = trunc(runif(15)*(15-1))+1)\r\n\r\ntestModUI <- function(id) {\r\n  ns <- NS(id)\r\n  tagList(\r\n    visNetworkOutput(ns(\"network\")), \r\n    verbatimTextOutput(ns(\"node_found\")),  \r\n    verbatimTextOutput(ns(\"shiny_return\"))  \r\n    \r\n  )\r\n}\r\n\r\n\r\ntestMod <- function(input, output,session, nodes,edges) {\r\n  ns <- session$ns\r\n  \r\n  output$network <- renderVisNetwork({\r\n    visNetwork(nodes, edges, \r\n               height = \"100%\", width = \"100%\",\r\n               main = \"\") %>%\r\n      visEvents(click = paste0(\"function(nodes){\r\n                Shiny.onInputChange('\",ns('click'),\"', nodes.nodes[0]);\r\n                ;}\")\r\n      )\r\n  })\r\n  output$node_found <- renderText(input$click)\r\n\r\n    \r\n  output$shiny_return <- renderPrint({\r\n    visNetworkProxy(\"network\") %>%\r\n      visNearestNodes(target = input$click)\r\n  })\r\n}\r\n\r\nserver <- function(input, output, session) {\r\n  callModule(testMod,\"lookAtNearest\", nodes,edges)\r\n\r\n  }\r\n\r\nui <- fluidPage(\r\n  testModUI(\"lookAtNearest\")\r\n)\r\n\r\nshiny::shinyApp(ui = ui, server = server)`\r\n"},"comment":{"url":"https://api.github.com/repos/datastorm-open/visNetwork/issues/comments/376214570","html_url":"https://github.com/datastorm-open/visNetwork/issues/243#issuecomment-376214570","issue_url":"https://api.github.com/repos/datastorm-open/visNetwork/issues/243","id":376214570,"user":{"login":"bthieurmel","id":8750326,"avatar_url":"https://avatars2.githubusercontent.com/u/8750326?v=4","gravatar_id":"","url":"https://api.github.com/users/bthieurmel","html_url":"https://github.com/bthieurmel","followers_url":"https://api.github.com/users/bthieurmel/followers","following_url":"https://api.github.com/users/bthieurmel/following{/other_user}","gists_url":"https://api.github.com/users/bthieurmel/gists{/gist_id}","starred_url":"https://api.github.com/users/bthieurmel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bthieurmel/subscriptions","organizations_url":"https://api.github.com/users/bthieurmel/orgs","repos_url":"https://api.github.com/users/bthieurmel/repos","events_url":"https://api.github.com/users/bthieurmel/events{/privacy}","received_events_url":"https://api.github.com/users/bthieurmel/received_events","type":"User","site_admin":false},"created_at":"2018-03-26T15:49:22Z","updated_at":"2018-03-26T15:49:22Z","author_association":"CONTRIBUTOR","body":"Fix on github. And so the correct syntax is (after uptade package) : \r\n\r\n````\r\ntestMod <- function(input, output,session, nodes,edges) {\r\n  ns <- session$ns\r\n  \r\n  output$network <- renderVisNetwork({\r\n    visNetwork(nodes, edges,\r\n               height = \"100%\", width = \"100%\",\r\n               main = \"\") %>%\r\n      visEvents(click = paste0(\"function(nodes){\r\n                               Shiny.onInputChange('\",ns('click'),\"', nodes.nodes[0]);\r\n                               ;}\")\r\n      )\r\n  })\r\n  \r\n  output$node_found <- renderText(input$click)\r\n  \r\n  output$shiny_return <- renderPrint({\r\n    visNetworkProxy(ns(\"network\")) %>%\r\n      visNearestNodes(target = input$click)\r\n  })\r\n}\r\n````"}}
{"actor":{"display_login":"bthieurmel"}}