---
title: "GETable Usage"
author: "Yongfu Liao"
date: "`r Sys.Date()`"
output: 
  html_document:
    includes:
      in_header: dfFromWeb.html
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```


```{r}
library(getable)
```


## Table from a CSV file

This table is generated from a locally served CSV file^[You may want to set `echo=FALSE` to hide the code chunk.]:

```{r}
write.csv(iris, "data/df.csv")
renderTable("data/df.csv")
```



## Table from a JSON file

This table is generated from a JSON file on GitHub:

```{r}
renderTable("https://raw.githubusercontent.com/liao961120/getable/master/docs/demo/data/df.json")
```

Alternatively, you can use `getable::from_repo()`
to help you construct the url:

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


Note the JSON format of the source data in `df.json`:

```json
[
  {
    "colname1": "value1-1",
    "colname2": "value1-2",
    "colname3": "value1-3"
  },
  {
    "colname1": "value2-1",
    "colname2": "value2-2",
    "colname3": "value2-3"
  },
  ...
]
```

You can convert data frames to this format simply with `jsonlite::toJSON(df, dataframe = "rows")` or save it to a json text file with `getable::df2file()`:


```{r}
df <- data.frame(
  id = 1:2,
  name = c("john", "smith"),
  phone = c("3366-3366", "02-3366-3366")
)

getable::df2json(df, "data/df.json")
```



## Table from Google Spreadsheet

```{r}
getable::renderTable("https://docs.google.com/spreadsheets/d/1KV8XOlBcax3gca5s6Wl7M06nVrpui39hHGXDv-K6gM8/edit?usp=sharing")
```

In order to use this feature, make sure that the google spreadsheet is [**viewable** for anyone who has the link](https://support.google.com/drive/answer/2494822#link_sharing).



## Styling the table

Edit the styles in `dfFromWeb.css` to style the table.
