显示情节轮廓,边框

时间:2018-03-07 23:33:28

标签: r shiny vis.js visnetwork

使用 visNetwork 包,我们如何添加边框?

参考: GitHubCRANOnline documentation

library(visNetwork)

nodes <- data.frame(id = 1:3, 
                    color.background = c("red", "blue", "green"),
                    color.highlight.background = c("red", NA, "red"), 
                    shadow.size = c(5, 10, 15))

edges <- data.frame(from = c(1,2), to = c(1,3),
                    label = LETTERS[1:2], 
                    font.color =c ("red", "blue"), 
                    font.size = c(10,20))

visNetwork(nodes, edges)

我们可以设置背景颜色,但我更喜欢绘图的轮廓/边框。

如果它是相关的,我在有光泽的中使用它,这是一个例子:

library(shiny)
library(visNetwork)

shinyApp(
  ui = fluidPage(
    visNetworkOutput("vis1", height = "200px"),
    visNetworkOutput("vis2", height = "200px")
  ),

  server = function(input, output, session) {
    nodes <- data.frame(id = 1:3, group = c("B", "A", "B"))
    edges <- data.frame(from = c(1,2), to = c(2,3))

    output$vis1 <- renderVisNetwork({
      visNetwork(nodes, edges,
                 main = "my vis 1")
      })
    output$vis2 <- renderVisNetwork({
      visNetwork(nodes, edges, background = "red",
                 main = "my vis 2, with red background")
    })

  })

并希望看到情节的轮廓,这里首先是vis(vis1)没有轮廓,只是透明的背景,很难说边界在哪里:

enter image description here

1 个答案:

答案 0 :(得分:2)

您可以选择CSS解决方案,因为此上下文具有闪亮特定性。

library(shiny)
library(visNetwork)

shinyApp(
  ui = fluidPage(

    tags$head(
      tags$style(HTML("
                      #vis1 {
                        border: 2px solid black;
                      }
                      "))
      ),

    visNetworkOutput("vis1", height = "200px"),
    visNetworkOutput("vis2", height = "200px")
  ),

  server = function(input, output, session) {
    nodes <- data.frame(id = 1:3, group = c("B", "A", "B"))
    edges <- data.frame(from = c(1,2), to = c(2,3))

    output$vis1 <- renderVisNetwork({
      visNetwork(nodes, edges,
                 main = "my vis 1")
    })
    output$vis2 <- renderVisNetwork({
      visNetwork(nodes, edges, background = "red",
                 main = "my vis 2, with red background")
    })

  })

我还建议将CSS放在自己的样式表中。 有关如何完成此操作,请参阅this guide