Skip to content

prototype HTTP server to dynamically render parameterized Rmarkdown files

Notifications You must be signed in to change notification settings

CRI-iAtlas/rmarkdown-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RMarkdown Server

WARNING: This is a proof of concept only. It is not ready for production.

A simple HTTP server written in R that serves up parameterized RMarkdown files. The key difference compared to services like http://rpubs.com is the RMarkdown files are re-rendered with each unique set of parameter-values passed in the query string.

Any Rmd file in ./public can be served. Parameters are expressed in standard RMarkdown metadata. Read more about RMarkdown params here: https://bookdown.org/yihui/rmarkdown/.

The server translates any query-params passed in the URL to the RMarkdown file via the rmarkdown::render() params argument.

Setup

Make sure you have R installed. RStudio is not strictly required, but we'll assume you are using it:

Git-clone this repository and then open rmarkdown-server.RProj. Install the required packages by executing this in the RSudio console:

renv::restore()

Start, Stop, Restart the Server

start or restart server:

source('./server.R')

stop server:

.GlobalEnv$runningServer$stopServer()

API

/ Get Rendered RMarkdown File with Params

Get a rendered rmarkdown file:

The .Rmd extension is optional:

Pass params in the query string:

/params/ Get Params Metadata for RMarkdown File

Precede the path with /params/ to get a JSON object directly derived from the params property in the Rmarkdown file's metadata:

leaflet.Rmd metadata:

title: Leaflet Demo
output: html_document
params:
  tiles:
    label: "Tiles"
    value: "normal"
    input: "select"
    choices:
      - "normal"
      - "monochrome"

/params/leaflet.Rmd output:

{
  "tiles": {
    "label": [
      "Tiles"
    ],
    "value": [
      "normal"
    ],
    "input": [
      "select"
    ],
    "choices": [
      "normal",
      "monochrome"
    ]
  }
}

The .Rmd extension is optional:

Production TODO

Currently a url could have "/../" in the path and give access outside public/.

About

prototype HTTP server to dynamically render parameterized Rmarkdown files

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages