简体   繁体   English

为什么在尝试使用 R Shiny 和 networkD3 制作桑基图时会出现“缺少参数”输出,没有默认值”?

[英]Why do I get "argument "output" is missing, with no default" when trying to make a sankey plot with R shiny and networkD3?

I am trying to make a shiny App in R via the networkD3 example.我正在尝试通过 networkD3 示例在 R 中制作一个闪亮的应用程序。 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)

You should assign your UI to ui, and your server function to a variable called server .您应该将您的UI分配给 ui,并将您的server功能分配给一个名为server的变量。 Those are then passed as arguments in your last line shinyApp(ui,server) .然后将它们作为参数传递到最后一行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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 R:networkD3 sankey图-颜色未显示 - R: networkD3 sankey plot - colours not displaying Networkd3 Sankey图表中的返回节点名称(R /发光) - Return node name in a Networkd3 Sankey Chart (R/Shiny) 我可以旋转 Sankey Plot (networkD3::sankeyNetwork) 中的节点标签吗? - Can I rotate the node labels in a Sankey Plot (networkD3::sankeyNetwork)? 带有networkD3包的Sankey Diagram不会绘图 - Sankey Diagram with networkD3 package will not plot 使用 networkD3 在 R 中的 Sankey 图表中进行交互 - Interactivity in Sankey chart in R using networkD3 如何在每个节点下方使用 R networkD3 值和百分比绘制 Sankey Graph - How to plot Sankey Graph with R networkD3 values and percentage below each node R中的NetworkD3 Sankey Plot:如何仅将文本标签从内部节点的右侧切换到左侧 - NetworkD3 Sankey Plot in R: How to switch text labels from the right to the left of the inner nodes only networkD3(Sankey)和sunburstR(Sanburst)包不能在Shiny中一起使用 - networkD3 (Sankey) and sunburstR (Sanburst) package can not be useed together in Shiny 如何将链接标签的字体大小更改为在 R 中使用 networkd3 构建的 Sankey 图? - How can I change the font size of link labels to a Sankey Diagram built with networkd3 in R? 使用用户定义的颜色修改networkD3 sankey图 - Modify networkD3 sankey plot with user-defined colors
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM