Package 'getable'

Title: Fetching Tabular Data "Onload" in Compiled R Markdown HTML Documents
Description: Dynamically retrieve data from the web to render HTML tables on inspection in R Markdown HTML documents.
Authors: Yongfu Liao [aut, cre]
Maintainer: Yongfu Liao <[email protected]>
License: MIT + file LICENSE
Version: 1.0.3
Built: 2024-11-05 05:43:09 UTC
Source: https://github.com/liao961120/getable

Help Index


Convert Data Frame to Valid JSON Format for Serving

Description

Convert Data Frame to Valid JSON Format for Serving

Usage

df2json(df, output = "./data/df.json", ...)

Arguments

df

A data frame.

output

A string. The path to the exported data frame.

...

Additional arguments arguments passed on to toJSON.


Build URL to a file from GitHub Repository

Description

This function builds a URL in the form: https://raw.githubusercontent.com/<username>/<repo>/<branch>/<path>.

Usage

from_repo(username, repo, path, branch = "master")

Arguments

username

A string. The owner of the repo.

repo

A string. The name of the repo.

path

A string. The path to the file.

branch

A string. The branch the file is on.

Value

An URL to the path.

Examples

from_repo(
    username = "liao961120",
    repo = "getable",
    path = "docs/demo/data/df.json",
    branch = "master")
renderTable(
  from_repo(
    username = "liao961120",
    repo = "getable",
    path = "docs/demo/data/df.json",
    branch = "master")
)

Render HTML Table in R Markdown with Data from Web

Description

This function is expected to work with getable's R Markdown template, which contains an .html file, a .js file, and a .css file in addition to the .Rmd source file. The function creates an HTML string and insert it into the HTML file rendered from Rmd. The code in the .js file then process the HTML string and retrieve data from web to create an HTML table dynamically when users view the rendered HTML file in the browser (a server is needed to served the file).

Usage

renderTable(url = "./data/df.csv", isjson = FALSE)

Arguments

url

A string. The URL to the source data of the table to be created. Could be a relative path (relative to the .Rmd src file) or an URL to a JSON or CSV file. url could also be an URL to a publicly viewable Google Spreadsheet. Defaults to ./data/df.csv (see the template's structure).

isjson

Boolean. Whether the format of the self-hosted file is json. Defaults to FALSE. Works only when the data is self-hosted (i.e. not from Google Spreadsheet).

Value

A string representing an HTML div tag.

Examples

renderTable("https://raw.githubusercontent.com/liao961120/getable/master/docs/demo/data/df.csv")