52North / sensorweby

A JavaScript sensor web client with graphs and analytics powered by Shiny
GNU General Public License v3.0
8 stars 5 forks source link

list available examples when calling runExample() without arguments #4

Open nuest opened 9 years ago

nuest commented 9 years ago

To replicate:

library(sensorweby)
?runExample
runExample()
runExample("not-there") # lists the existing shiny examples instead of the sensorweby examples
autermann commented 9 years ago

we can reuse this snippet:

listExamples <- function(package, blacklist = NULL) {
    dir <- paste(find.package(package), 'examples', sep='/')
    dirs <- list.dirs(dir, recursive=FALSE)
    if (!is.null(blacklist)) {
        dirs <- Reduce(intersect, lapply(blacklist, function(x) 
            dirs[!grepl(x, dirs, fixed=TRUE)]), dirs)    
    }
    examples <-  substr(dirs,  nchar(dir) + 2, nchar(dirs))
    htmltools::tag('ul', lapply(examples, function(x) 
        htmltools::tag('li', tagList(htmltools::a(href = paste(package, x, sep="/"), htmltools::code(x))))))
}

listExamples("sensorweby", blacklist = "iframe")