marineenergy / apps

shiny apps for MHK-env
https://marineenergy.github.io/apps/
MIT License
3 stars 1 forks source link

fold rest of content into output report #78

Closed bbest closed 2 years ago

bbest commented 2 years ago

Here's the content that is queryable in the app and folded into the output custom report:

image

bbest commented 2 years ago

Working off apps_dev branch in /share/github/apps_dev displayed in:

per:

ls -la  /srv/shiny-server
report-v2-dev -> /share/github/apps_dev/report-v2
bbest commented 2 years ago

app: report-v2

Purpose: configure the API request to generate the report.

Working off apps_dev branch in /share/github/apps_dev displayed in:

per:

ls -la  /srv/shiny-server
report-v2-dev -> /share/github/apps_dev/report-v2
  1. ui.R: btn_rpt_create: https://github.com/marineenergy/apps/blob/51380df264f05d73a7a5b3acaf5f0b18a7d4a2b6/report-v2/ui.R#L273

  2. server.R: input$btn_rpt_create: https://github.com/marineenergy/apps/blob/51380df264f05d73a7a5b3acaf5f0b18a7d4a2b6/report-v2/server.R#L717-L772

  3. Submits to the api url_rpt_pfx "https://api.marineenergy.app/report", which is the report endpoint of the https://api.marineenergy.app.

api: generate the report

  1. run-api.R#L5

    plumber_r <- "/share/github/api/plumber.R"
  2. plumber.R#L91-L154

    # TODO: reset default values to Null or blank
    function(
      req,
      email        = "bdbest@gmail.com",
      date         = "2021-05-25 19:11:49 UTC",
      title        = "Test Report",
      filetype     = "html",
      contents     = '{"Projects":[true],"Management":[true]}',
      interactions = '[["Receptor.Fish","Stressor.PhysicalInteraction.Collision"],["Technology.Wave","Receptor.Birds"]]',
      res) {
    ...
    dir_rpt_pfx <- "/share/user_reports"
    ...
    r_script    <- "/share/github/api/scripts/render_yml.R"
    ...
    # get hash for unique filename by digesting metadata
    hsh <- digest::digest(m, algo="crc32")
    yml <- glue::glue("{dir_rpt_pfx}/{email}/report_{hsh}.yml")
    ...
    cmd <- glue::glue('r_script={r_script}\n yml={yml}\n log={log}\n $r_script $yml > $log 2>> $log')
    ...
    system(cmd, wait = F)
  3. render_yml.R#L8-L73

    setwd("/share/github/api")
    template_rmd <- "/share/github/api/_report.Rmd"
    source("/share/github/apps_dev/scripts/common.R")
    source(file.path(dir_scripts, "report.R"))
    ...
    # write Rmd of custom report
    message("frontmatter for Rmd... ----")
    message(yaml::as.yaml(fm))
    ...
    message("rendering...")
    rmarkdown::render(
      input         = rmd,
      output_file   = out)
bbest commented 2 years ago

Let's look at example reports in /share/user_reports/ben@ecoquants.com that currently:

bbest commented 2 years ago

PROBLEM: Need tabular output for content without any interactions provided

The report API is only setup to write outputs per content type given a set of interactions (ie combinations of technology/stressor/receptor tags).

image

This is handled in render_yml.R#L64 with the rpt_content() function:

  r <- lapply(contents, rpt_content, ixns = p$interactions, rmd = rmd)

And this function is defined in:

https://github.com/marineenergy/apps/blob/51380df264f05d73a7a5b3acaf5f0b18a7d4a2b6/scripts/report.R#L14-L57

So need to make another option, like in render_yml.R#L64:

if (length(p$interactions) == 0) { 
  # TODO: return table of all content 
} else {
  # carry on as originally designed
  r <- lapply(contents, rpt_content, ixns = p$interactions, rmd = rmd)
}`