if(interactive()){
library(shiny)
ui <- fluidPage(
tags$label('Check if package "pkg1", "pkg2", "bioxxx",
github package "user1/pkg1" are installed'), br(),
actionButton("check_random_pkg", "check random_pkg"),
br(), spsHr(),
tags$label('We can combine `spsValidate` to block server code to prevent
crash if some packages are not installed.'), br(),
tags$label('If "shiny" is installed, make a plot.'), br(),
actionButton("check_shiny", "check shiny"), br(),
tags$label('If "ggplot99" is installed, make a plot.'), br(),
actionButton("check_gg99", "check ggplot99"), br(),
plotOutput("plot_pkg")
)
server <- function(input, output, session) {
observeEvent(input$check_random_pkg, {
shinyCheckPkg(session, cran_pkg = c("pkg1", "pkg2"),
bioc_pkg = "bioxxx", github = "user1/pkg1")
})
observeEvent(input$check_shiny, {
spsValidate(verbose = FALSE, {
if(!shinyCheckPkg(session, cran_pkg = c("shiny"))) stop("Install packages")
})
output$plot_pkg <- renderPlot(plot(1))
})
observeEvent(input$check_gg99, {
spsValidate({
if(!shinyCheckPkg(session, cran_pkg = c("ggplot99"))) stop("Install packages")
})
output$plot_pkg <- renderPlot(plot(99))
})
}
shinyApp(ui, server)
}
Run the code above in your browser using DataLab