ambiorix icon indicating copy to clipboard operation
ambiorix copied to clipboard

feat: check if a file / folder contains an ambiorix app

Open JosiahParry opened this issue 1 year ago • 2 comments

I use utility functions like this to determine if a folder / file contains a shiny app or plumber API.

I cannot come up with a way to do this for an ambiorix app.

Perhaps there can be a function that takes a file / path that contains an app and returns that Ambiorix object?

is_shiny_app <- function(path) {
  tryCatch(
    !is.null(shiny::shinyAppDir(path)),
    error = function(cond) FALSE
  )
}

is_plumber_api <- function(path) {
  tryCatch(
    length(plumber::plumb(dir = path)$routes) > 0,
    error = function(cond) FALSE
  )
}

JosiahParry avatar Jan 04 '25 20:01 JosiahParry

my thoughts on this so far are:

  1. we'd have to agree on a series of files to check since ambiorix does not dictate the file naming. good candidates for this:
    • app.R: a general name (kind of a consensus in the R community?)
    • index.R: for frontend apps
    • server.R: for JSON data APIs
  2. a very naive & brute-force approach would be to check for the existence of the string "Ambiorix$new" in the file (since that is the way to instantiate an ambiorix app).

kennedymwavu avatar Jan 17 '25 22:01 kennedymwavu

Here plumber and shiny use the principle of convention over configuration. In many other languages frameworks you have a routes file always in the same place and it's easy to check it. In Ambiorix, the creation and routes can be in any file (or inside another package) If we go for option 2, I think we could have has_ambiorix_new_dir function (or similar name) to make it clar that looks Ambiorix::new in all .R files of the directory.

jrosell avatar Jan 18 '25 11:01 jrosell