christophergandrud / networkD3

D3 JavaScript Network Graphs from R
http://christophergandrud.github.io/networkD3
649 stars 269 forks source link

simpleNetwork update with shiny textAreaInput - doesn't work #174

Closed teshomem closed 7 years ago

teshomem commented 7 years ago

Hi,

Thank you for the great application. Removing or updating textAreaInput to update existing network graph doesn't seem working. Please check the sample code:

#ui.R--------------------------------------------------
library(networkD3)

shinyUI(navbarPage(
  'D3 network',
  id = "page",
  collapsible = TRUE,
  inverse = FALSE,
  tabPanel("networkD3",
           tabsetPanel(
             tabPanel(
               "Simple Network",
               tags$p("\n"),
               tags$p(""),

               fluidRow(column(width = 2,
                               wellPanel(
                                 textAreaInput(
                                   "tarea",
                                   "Network Data",
                                   placeholder = 'A,B',
                                   value = 'AA,BB'

                                 )

                               )),

                        column(
                          width = 10,
                          fluidRow(
                            class = "tf_panels",
                            simpleNetworkOutput('simple', width = "100%", height = "800px")
                          )

                        ))
             )

           ))
))

#server.R-----------------------------------------------
library(shiny)
library(data.table)

data(MisLinks)
data(MisNodes)

shinyServer(function(input, output) {
  output$simple <- renderSimpleNetwork({
    src <- c("AA", "AA", "AA", "AA", "BB", "BB", "CC", "CC", "DD")
    target <- c("B", "C", "D", "J", "E", "F", "G", "H", "I")

    rawData <- data.table(src, target)

    userlist <-
      as.data.table(sub(" +|\n+", "", unlist(list(
        strsplit(input$tarea, ",")
      ))))

    networkData <- data.frame(rawData[src %in% userlist$V1,])
    simpleNetwork(Data = networkData)
  })

})

Thanks

cjyetman commented 7 years ago

I have a feeling you're running into the same problem as here #176.

Please try installing the dev branch to fix the forceNetwork centering and reheating issue with...

devtools::install_github('cjyetman/networkD3', ref = 'center_forceNetwork')

and let us know if that fixes your problem.

cjyetman commented 7 years ago

I'm gonna go ahead and close this as a dupe of #176 because I'm pretty certain that's why this wasn't working for you as expected. Feel free to comment if I'm wrong.

teshomem commented 7 years ago

Thanks a lot, the dev branch fix works.