Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JosiahParry opened this issue Jan 4, 2025 · 2 comments
Open

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

JosiahParry opened this issue Jan 4, 2025 · 2 comments

Comments

@JosiahParry
Copy link

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
  )
}
@kennedymwavu
Copy link
Contributor

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).

@jrosell
Copy link

jrosell commented Jan 18, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants