#!/usr/bin/env Rscript

arguments <- commandArgs(trailingOnly = TRUE)
port <- if (length(arguments) >= 1L) as.integer(arguments[[1]]) else 4287L

script_arguments <- commandArgs(trailingOnly = FALSE)
script_flag <- grep("^--file=", script_arguments, value = TRUE)
tests_directory <- dirname(normalizePath(sub("^--file=", "", script_flag[[1]])))
app_directory <- normalizePath(file.path(tests_directory, ".."))

shiny::runApp(
  appDir = app_directory,
  host = "127.0.0.1",
  port = port,
  launch.browser = FALSE
)
