1

I am trying to make a shiny App in R via the networkD3 example. My code is attached on the bottom.

I got the code from this page.

When I try to run this, I get this error message:

Error in shinyServer(function(input, output) { : 
  argument "output" is missing, with no default

Question: How do I fix the code to make it work?

library(shiny)
library(networkD3)
data(MisLinks)
data(MisNodes)

shinyUI(fluidPage(

  titlePanel("Shiny networkD3 "),

  sidebarLayout(
    sidebarPanel(
      numericInput("opacity", "Opacity", 0.6, min = 0.1, max = 1, step = .1)
    ),
    mainPanel(
      tabsetPanel(
        tabPanel("Simple Network", simpleNetworkOutput("simple")),
        tabPanel("Force Network", forceNetworkOutput("force")),
        tabPanel("Force Network with Legend & Radius", forceNetworkOutput("forceRadius")),
        tabPanel("Sankey Network", 
                 checkboxInput("sinksRight", "sinksRight", value = TRUE),
                 sankeyNetworkOutput("sankey")),
        tabPanel("Reingold-Tilford Tree", radialNetworkOutput("rt"))
      )
    )
  )
))

shinyServer(function(input, output) {


  output$sankey <- renderSankeyNetwork({
    URL <- "https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json"
    Energy <- jsonlite::fromJSON(URL)
    sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
                  Target = "target", Value = "value", NodeID = "name",
                  fontSize = 12, nodeWidth = 30, sinksRight = input$sinksRight)
  })



})

shinyApp(ui, server)
Florian
  • 24,425
  • 4
  • 49
  • 80
nexonvantec
  • 572
  • 1
  • 5
  • 18

1 Answers1

1

You should assign your UI to ui, and your server function to a variable called server. Those are then passed as arguments in your last line shinyApp(ui,server). Hope this helps!

Working code:

library(shiny)
library(networkD3)
data(MisLinks)
data(MisNodes)

ui <- shinyUI(fluidPage(

  titlePanel("Shiny networkD3 "),

  sidebarLayout(
    sidebarPanel(
      numericInput("opacity", "Opacity", 0.6, min = 0.1, max = 1, step = .1)
    ),
    mainPanel(
      tabsetPanel(
        tabPanel("Simple Network", simpleNetworkOutput("simple")),
        tabPanel("Force Network", forceNetworkOutput("force")),
        tabPanel("Force Network with Legend & Radius", forceNetworkOutput("forceRadius")),
        tabPanel("Sankey Network", 
                 checkboxInput("sinksRight", "sinksRight", value = TRUE),
                 sankeyNetworkOutput("sankey")),
        tabPanel("Reingold-Tilford Tree", radialNetworkOutput("rt"))
      )
    )
  )
))

server <- function(input, output) {


  output$sankey <- renderSankeyNetwork({
    URL <- "https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json"
    Energy <- jsonlite::fromJSON(URL)
    sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
                  Target = "target", Value = "value", NodeID = "name",
                  fontSize = 12, nodeWidth = 30, sinksRight = input$sinksRight)
  })



}

shinyApp(ui, server)
Florian
  • 24,425
  • 4
  • 49
  • 80