diff --git a/DESCRIPTION b/DESCRIPTION index a7d9edd..020a6f4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,8 +27,7 @@ Imports: tibble, aplot, forcats, - tidyr, - shiny + tidyr URL: https://github.com/gaospecial/ggVennDiagram, https://gaospecial.github.io/ggVennDiagram/ License: GPL-3 Encoding: UTF-8 @@ -40,6 +39,7 @@ Suggests: knitr, rmarkdown, venn, - RColorBrewer + RColorBrewer, + shiny VignetteBuilder: knitr LazyData: true diff --git a/R/check_pakage.R b/R/check_pakage.R new file mode 100644 index 0000000..d87c5d6 --- /dev/null +++ b/R/check_pakage.R @@ -0,0 +1,8 @@ +check_package = function(package = "ggVennDiagram"){ + if (!requireNamespace(package, quietly = TRUE)){ + stop(paste("The", package, "package is not found in your library paths.", + " It is required to show intersections interactively.", + " Please run `install.packages('package')` and retry.", + collapse = "\n")) + } +} diff --git a/R/ggVennDiagram.R b/R/ggVennDiagram.R index 3a7a8fc..ce0e1aa 100644 --- a/R/ggVennDiagram.R +++ b/R/ggVennDiagram.R @@ -151,7 +151,7 @@ plot_venn = function(data, # use plotly to show intersect if (show_intersect){ - check_plotly() + check_package("plotly") region_label = region_label |> dplyr::rowwise() |> dplyr::mutate(item = str_wrap(paste0(.data$item, collapse = " "), @@ -202,17 +202,6 @@ plot_venn = function(data, } - -check_plotly = function(){ - if (!requireNamespace("plotly", quietly = TRUE)){ - stop(paste("The plotly package is not found in your library paths.", - " It is required to show intersections interactively.", - " Please run `install.packages('plotly')` and retry.", - collapse = "\n")) - } -} - - # from yulab.utils::str_wrap str_wrap = function (string, width = getOption("width")){ result <- vapply(string, FUN = function(st) { diff --git a/R/launch_app.R b/R/launch_app.R index 9576ba2..b1a7cbe 100644 --- a/R/launch_app.R +++ b/R/launch_app.R @@ -3,11 +3,12 @@ #' @return a shiny app #' @export launch_app = function(){ + check_package("shiny") app = system.file( "shiny", "shinyApp.R", package = "ggVennDiagram", mustWork = TRUE ) - shiny::runApp(app) + if(interactive()) shiny::runApp(app) } diff --git a/inst/shiny/shinyApp.R b/inst/shiny/shinyApp.R index ec9c0bf..0947ec2 100644 --- a/inst/shiny/shinyApp.R +++ b/inst/shiny/shinyApp.R @@ -26,7 +26,8 @@ ui = fluidPage( actionButton( inputId = "increase_btn", label = "increase the no. of set", - icon = icon("caret-up") + icon = icon("caret-up"), + align = "right" ), hr(), @@ -90,11 +91,11 @@ server = function(input, output, session){ # initialize plot note output$plot_note = renderUI({ tagList( - h3("Steps"), - p("1. Use the button or slider to set the no. of sets."), - p("2. Specify set members using comma-sparated strings."), - p("3. Click the button."), - p("4. Enjoy and download your publication-quality figures.") + markdown("### Steps"), + markdown("1. Use the button or slider to specify the number of sets."), + markdown("2. Specify set members using comma-sparated strings (just follow the examples)."), + markdown("3. Click the **** button."), + markdown("4. Enjoy and download your publication-quality figures.") ) })