Closed redstplr closed 5 years ago
library(shinydashboard) library(visNetwork) library(magrittr) library(shiny)
header <- dashboardHeader(title = "visNetwork Graph")
sidebar <- dashboardSidebar( sidebarMenu( menuItem("visNetwork", tabName = "graph", icon = NULL) ) )
body <- dashboardBody( tabItems( tabItem(tabName = "graph", fluidPage( visNetworkOutput("le_graph", width = "100%", height = "600px") ) ) ) )
dashboardUI <- dashboardPage(header, sidebar, body, skin = "red")
shinyUI <- fluidPage( visNetworkOutput("le_graph", width = "100%", height = "600px") ) )
SERVER <- function(input, output) { output$le_graph <- renderVisNetwork({ nodes <- data.frame(id = 1:3, group = c("B", "A", "B")) edges <- data.frame(from = c(1,2), to = c(2,3))
visNetwork(nodes = nodes, edges = edges, main = "Attack Paths", width = "100%", height = "600px") %>% visEdges(arrows = "to") %>% visGroups(groupname = "A", shape = "icon", icon = list(code = "f007", size = 75)) %>% visGroups(groupname = "B", shape = "icon", icon = list(code = "f0c0", color = "#f46d43")) %>% addFontAwesome() %>% visIgraphLayout() %>% visOptions(manipulation = TRUE, nodesIdSelection = TRUE, highlightNearest = list(enabled = T, degree = 2, hover = T))
}) }
dashboardapp <- shinyApp(ui = dashboardUI, server = SERVER) shinyapp <- shinyApp(ui = shinyUI, server = SERVER)
runApp(dashboardapp) # does not work runApp(shinyapp) # does work
Solution: https://github.com/datastorm-open/visNetwork/issues/292
Example
library(shinydashboard) library(visNetwork) library(magrittr) library(shiny)
Build a shinydashboard UI
header <- dashboardHeader(title = "visNetwork Graph")
sidebar <- dashboardSidebar( sidebarMenu( menuItem("visNetwork", tabName = "graph", icon = NULL) ) )
body <- dashboardBody( tabItems( tabItem(tabName = "graph", fluidPage( visNetworkOutput("le_graph", width = "100%", height = "600px") ) ) ) )
dashboardUI <- dashboardPage(header, sidebar, body, skin = "red")
Build a standard shiny UI
shinyUI <- fluidPage( visNetworkOutput("le_graph", width = "100%", height = "600px") ) )
Application server
SERVER <- function(input, output) { output$le_graph <- renderVisNetwork({ nodes <- data.frame(id = 1:3, group = c("B", "A", "B")) edges <- data.frame(from = c(1,2), to = c(2,3))
}) }
Application
dashboardapp <- shinyApp(ui = dashboardUI, server = SERVER) shinyapp <- shinyApp(ui = shinyUI, server = SERVER)
Fontawesome icons do not render in the shinydashboard application
runApp(dashboardapp) # does not work runApp(shinyapp) # does work