create custom tabs in newer (> 1.1) version of SPS. The old creation functions will be deprecated by next Bioconductor major release.
spsNewTab( tab_id = "vs_mytab", tab_displayname = "My custom plotting tab", img = "", app_path = getwd(), out_folder_path = file.path(app_path, "R"), author = "", template = c("simple", "full"), preview = FALSE, reformat = FALSE, open_file = TRUE, verbose = spsOption("verbose"), colorful = spsOption("use_crayon") )
tab_id | character string, length 1, must be unique. Use spsTabInfo(app_path = "YOUR_APP_PATH") to see current tab IDs. |
---|---|
tab_displayname | character string, length 1, the name to be displayed on side navigation bar list and tab title |
img | realtive path, an image representation of the new plot. It can be a internet link or a local link which uses the www folder as the root. e.g. drop your image plot.png inside www/plot_list, then the link here is "plot_list/plot.png". You will see these images on "Custom Tabs" main page. If no provided, a warning will be given on app start and an empty image will show up on "Custom Tabs". |
app_path | string, app directory, default is current directory |
out_folder_path | string, which directory to write the new tab file, default is the R folder in the SPS project. If you write the file other than R, this file will not be automatically loaded by SPS or Shiny. You must source it manually. |
author | character string, or a vector of strings. authors of the tab |
template | one of "simple" or "full", default "simple". "simple" gives a tab file with minimum Shiny code, you can only focus on you R plotting code. "full" gives the full tab code, so you can modify everything on the tab. |
preview | bool, TRUE will print the new tab code to console and will not write the file and will not register the tab |
reformat | bool, whether to use styler::style_file reformat the code |
open_file | bool, if Rstudio is detected, open the new tab file? |
verbose | bool, default follows the project verbosity level. TRUE will give you more information on progress and debugging |
colorful | bool, whether the message will be colorful or not |
returns a new tab file
template "simple": hides the UI and server code and use spsEzUI and spsEzServer instead.
template "full": full tab code. You need to know some Shiny development knowledge.
#>#> Warning: [SPS-WARNING] 2021-09-18 02:42:32 Overwrite things in /home/runner/work/systemPipeShiny/systemPipeShiny/docs/reference/SPS_20210918#>#>#>#>#> [SPS-DANGER] 2021-09-18 02:42:32 Done, Db created at '/home/runner/work/systemPipeShiny/systemPipeShiny/docs/reference/SPS_20210918/config/sps.db'. DO NOT share this file with others or upload to open access domains. #> [SPS-INFO] 2021-09-18 02:42:32 Key md5 bee8fd2eb20752e94288c4d41ca95876 #> [SPS-INFO] 2021-09-18 02:42:32 SPS project setup done!#>#>#>#>#>#>#>#>#>#> [SPS-SUCCESS] 2021-09-18 02:42:33 New tab created! #> [SPS] 2021-09-18 02:42:33 To load this new tab: `sps(tabs = c("vs_newtab_ez")`spsNewTab("vs_newtab_full", template = "full", app_path = glue::glue("SPS_{format(Sys.time(), '%Y%m%d')}"))#>#>#>#>#>#>#>#>#>#> [SPS-SUCCESS] 2021-09-18 02:42:33 New tab created! #> [SPS] 2021-09-18 02:42:33 To load this new tab: `sps(tabs = c("vs_newtab_full")`spsNewTab("vs_newtab_pre", preview = TRUE, app_path = glue::glue("SPS_{format(Sys.time(), '%Y%m%d')}"))#>#>#>#>#>#>#> ######################SPS My custom plotting tab tab###################### #> ## creation date: 2021-09-18 02:42:33 #> ## Author: #> #> # vs_newtab_pre UI #> vs_newtab_preUI <- spsEzUI( #> desc = " #> This tab is created by the `spsNewTab` function. #> #> #### Write some description of this tab in markdown format #> - you should ... #> 1. eg 1. #> 2. eg 2. #> - **Notice**: ...`this` ... #> #> #> ``` #> some code demo ... #> ``` #> ", #> tab_title = "My custom plotting tab", #> plot_title = "My Plot", #> plot_control = shiny::tagList( #> # add some UI to toggle different plot options in a `tagList` #> # this example adds a text input to allow users to modify plot title, #> # see server code on how we can use it. #> # remember to add `ns('ID')` around your ID. All tabs in SPS are built on #> # top of Shiny modules, use `ns()` to indicate namespace. This function #> # is not found when you write it, but will be valid once SPS runs it. #> shiny::fluidRow( #> class = "center-child", #> clearableTextInput( #> inputId = ns("plot_title"), #> label = "Plot title", #> value = "Example plot" #> ) #> ) %>% #> bsHoverPopover("Plot title", "Type your plot title", placement = "top") #> ) #> ) #> #> # vs_newtab_pre server #> vs_newtab_preServer <- spsEzServer( #> plot_code = { #> # data passed from data loading is a reactiveValues object, data stored in `mydata$data` #> plot_data <- mydata$data #> # some validations, make sure users give you the right data format #> spsValidate({ #> stopifnot(inherits(plot_data, "data.frame")) # require a dataframe #> stopifnot(nrow(plot_data) > 1) # has least one row #> if (!all(c("Sepal.Length", "Sepal.Width") %in% colnames(plot_data)))# has two required columns #> stop("Require column 'Sepal.Length' and 'Sepal.Width'") #> #> TRUE # give it a TRUE if all checks passed. #> }, #> verbose = FALSE # only show messages when fail #> ) #> # actual plot code #> ggplot2::ggplot(plot_data) + #> ggplot2::geom_point(ggplot2::aes(x = Sepal.Length, y = Sepal.Width)) + #> # grab user defined title from plot control by `input$+control_ID`, #> # no need to add `ns()` on server end. #> ggplot2::ggtitle(input$plot_title) #> }, #> other_server_code = { #> # additional server code for this tab you want to run #> msg("My tab xxx runs", "", "green") #> } #> )