在 Shiny R 中显示 VennDiagram

Display a VennDiagram in Shiny R

我想在 Shiny R 中交互式地显示一个 VennDiagram::venn.diagram()

但是,函数 venn.diagram() 需要 filename 属性,因为它会生成外部 TIFF 文档。

因此,我应该使用什么函数来根据用户输入动态生成维恩图 (input$SELECTION)?

我想我应该使用函数draw.single.venndraw.triple.venndraw.pairwise.venndraw.quad.venn,但我不知道高级有多少 我需要维恩斯。

library(shiny)
library(Venn.Diagram)

# Define UI ----
ui <- fluidPage(
  titlePanel("Title"),
  
  sidebarLayout(
    sidebarPanel(
      
      checkboxGroupInput(
        "SELECTION",
        label = "Select your subsets",
        choices = list("Web of Science" = "WoS",
                       "Scopus" = "Scopus",
                       "Dimensions" = "Dimensions",
                       "LENS" = "LENS"),
        selected = c("WoS", "Scopus")
      ),

    mainPanel(
      plotOutput("venn")
    )
  )
)

# Define server logic ----
server <- function(input, output) {
  
  output$venn <- renderPlot({

    data <- list(WoS=c("ff", "gg"), Scopus=c("ff", "gg"), Dimensions=c("ff", "gg"), LENS=c("ff", "gg"))
    
    # select only those elements that are named in input$SELECTION
    data <- data[input$SELECTION]
    
    # this will not work
    venn.diagram(data)
  })
  
}

# Run the app ----
shinyApp(ui = ui, server = server)

Limey 在评论中发布了正确答案,来自 this source

首先,我添加了这个功能:

display_venn <- function(x, ...){
  library(VennDiagram)
  grid.newpage()
  venn_object <- venn.diagram(x, filename = NULL, ...)
  grid.draw(venn_object)
}

其次,我用display_venn(data)替换了venn.diagram(data)