以下闪亮的应用无法呈现网络图。而使用Rmd文件我得到了图形。下面是一个可重复的例子。热衷于知道错误在哪里(如果有的话)。
library(shiny)
library(shinythemes)
library(networkD3)
library(data.tree)
library(tidyr)
# Define UI for application that draws a network graph
ui <- fluidPage(theme = shinytheme("slate"),
sliderInput("number",
"Random Numbers:",
min = 1,
max = 100,
value = 20),
# Show a plot of the generated distribution
radialNetworkOutput("radial")
)
# Define server logic required to draw a network graph
server <- function(input, output) {
Data_tree <- reactive({
data.frame(Start="Class",
Asset = sample(c("FI","Equity","Currency"),input$number,replace = TRUE),
Sub_Asset = sample(c("Asia","Europe","USA"),input$number,replace = TRUE),
Ticker = replicate(input$number,paste0(sample(LETTERS,3),collapse=""))) %>%
unite(col="pathString",Start,Asset,Sub_Asset,Ticker,sep="-",remove=FALSE) %>%
select(-Start) %>% as.Node(pathDelimiter = "-")
})
output$radial <- renderRadialNetwork({
# draw the radialNetwork with the specified size
ToListExplicit(Data_tree(), unname = TRUE )
})
}
# Run the application
shinyApp(ui = ui, server = server)
答案 0 :(得分:0)
刚刚发现代码中的短缺。在renderRadialNetwork函数中需要添加radialNetwork()
这是最终的工作代码。
library(shiny)
library(shinythemes)
library(networkD3)
library(data.tree)
library(tidyr)
# Define UI for application that draws a network graph
ui <- fluidPage(theme = shinytheme("slate"),
sliderInput("number",
"Random Numbers:",
min = 1,
max = 100,
value = 20),
# Show a plot of the generated distribution
radialNetworkOutput("radial")
)
# Define server logic required to draw a network graph
server <- function(input, output) {
Data_tree <- reactive({
data.frame(Start="Class",
Asset = sample(c("FI","Equity","Currency"),input$number,replace = TRUE),
Sub_Asset = sample(c("Asia","Europe","USA"),input$number,replace = TRUE),
Ticker = replicate(input$number,paste0(sample(LETTERS,3),collapse=""))) %>%
unite(col="pathString",Start,Asset,Sub_Asset,Ticker,sep="-",remove=FALSE) %>%
select(-Start) %>% as.Node(pathDelimiter = "-")
})
output$radial <- renderRadialNetwork({
# draw the radialNetwork with the specified size
radialNetwork(ToListExplicit(Data_tree(), unname = TRUE ), linkColour = "#ccc",nodeColour = "#fff",
nodeStroke = "orange",textColour = "#cccccc")
})
}
# Run the application
shinyApp(ui = ui, server = server)