Skip to content

Commit d48a03b

Browse files
authored
updates for v0.1.1
updates for v0.1.1
2 parents 84bc964 + 2dddae2 commit d48a03b

23 files changed

+590
-1422
lines changed

DESCRIPTION

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
Package: GWalkR
22
Title: Interactive Exploratory Data Analysis Tool
3-
Version: 0.1.0
3+
Version: 0.1.1
44
Authors@R: c(
55
person("Yue", "Yu", , "[email protected]", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0002-9302-0793")),
77
person("Kanaries Data Inc.", role = c("cph", "fnd")))
88
Maintainer: Yue Yu <[email protected]>
9-
Description: Simplify your R data analysis and data visualization workflow, by turning your data frame into a 'Tableau' style User Interface for visual exploration.
9+
Description: Simplify your R data analysis and data visualization workflow by turning your data frame into an interactive 'Tableau'-like interface, leveraging the 'graphic-walker' JavaScript library and the 'htmlwidgets' package.
1010
License: Apache License (>= 2)
1111
Encoding: UTF-8
1212
Roxygen: list(markdown = TRUE)
1313
RoxygenNote: 7.2.3
1414
URL: https://github.com/Kanaries/GWalkR/
15+
BugReports: https://github.com/Kanaries/GWalkR/issues
1516
Imports:
1617
htmlwidgets,
1718
jsonlite,
19+
openssl,
20+
shiny

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ export(gwalkr)
44
export(gwalkrOutput)
55
export(renderGwalkr)
66
import(htmlwidgets)
7+
import(openssl)
8+
import(shiny)

R/data_parser.R

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
raw_fields <- function(df) {
1+
library(openssl)
2+
3+
raw_fields <- function(df, columnSpecs = list()) {
4+
validate_columnSpecs(columnSpecs)
25
cols <- colnames(df)
36
props <- lapply(seq_along(cols), function(i) {
4-
infer_prop(cols[i], i, df)
7+
infer_prop(cols[i], i, df, columnSpecs)
58
})
69
return(props)
710
}
811

9-
infer_prop <- function(col, i = NULL, df) {
12+
infer_prop <- function(col, i = NULL, df, columnSpecs = list()) {
1013
s <- df[[col]]
11-
semantic_type <- infer_semantic(s)
12-
analytic_type <- infer_analytic(s)
14+
semantic_type <- ifelse((col %in% names(columnSpecs)), columnSpecs[[col]]$semanticType, infer_semantic(s))
15+
analytic_type <- ifelse((col %in% names(columnSpecs)), columnSpecs[[col]]$analyticalType, infer_analytic(s))
1316
prop <- list(
14-
fid = col,
17+
fid = fname_encode(col),
1518
name = col,
1619
semanticType = semantic_type,
1720
analyticType = analytic_type
@@ -41,4 +44,51 @@ infer_analytic <- function(s) {
4144
} else {
4245
return('dimension')
4346
}
47+
}
48+
49+
validate_columnSpecs <- function(columnSpecs) {
50+
acceptable_analyticalTypes <- c("measure", "dimension")
51+
acceptable_semanticTypes <- c("quantitative", "temporal", "nominal", "ordinal")
52+
53+
# Check that columnSpecs is a list
54+
if (!is.list(columnSpecs)) {
55+
stop("columnSpecs should be a list.")
56+
}
57+
58+
for (column in names(columnSpecs)) {
59+
# Check that the column specification is a list
60+
if (!is.list(columnSpecs[[column]])) {
61+
stop(paste0("The specification for '", column, "' should be a list."))
62+
}
63+
64+
# Check that the analyticalType and semanticType are specified
65+
if (!"analyticalType" %in% names(columnSpecs[[column]]) ||
66+
!"semanticType" %in% names(columnSpecs[[column]])) {
67+
stop(paste0("Both 'analyticalType' and 'semanticType' should be specified for '", column, "'."))
68+
}
69+
70+
# Check that the analyticalType and semanticType have acceptable values
71+
if (!(columnSpecs[[column]]$analyticalType %in% acceptable_analyticalTypes)) {
72+
stop(paste0("The 'analyticalType' for '", column, "' is invalid. It should be either 'measure' or 'dimension'."))
73+
}
74+
75+
if (!(columnSpecs[[column]]$semanticType %in% acceptable_semanticTypes)) {
76+
stop(paste0("The 'semanticType' for '", column, "' is invalid. It should be one of 'quantitative', 'temporal', 'nominal', or 'ordinal'."))
77+
}
78+
}
79+
}
80+
81+
fname_encode <- function(fname) {
82+
# Convert fname to base64
83+
return(base64_encode(charToRaw(as.character(fname))))
84+
}
85+
86+
fname_decode <- function(fname) {
87+
# Convert base64 back to string
88+
decoded <- rawToChar(base64_decode(fname))
89+
if (grepl("_", decoded)) {
90+
return(unlist(strsplit(decoded, "_"))[1])
91+
} else {
92+
return(decoded)
93+
}
4494
}

R/gwalkr.R

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,41 @@
33
#' Use this function to create a GWalkR interface from a given data frame in your "Viewer" window, and start your data exploration! Please make sure the width and the height of your "Viewer" window are large enough.
44
#'
55
#' @import htmlwidgets
6+
#' @import openssl
67
#'
78
#' @param data A data frame to be visualized in the GWalkR. The data frame should not be empty.
89
#' @param lang A character string specifying the language for the widget. Possible values are "en" (default), "ja", "zh".
10+
#' @param columnSpecs An optional list of lists to manually specify the types of some columns in the data frame.
11+
#' Each top level element in the list corresponds to a column, and the list assigned to each column should have
12+
#' two elements: `analyticalType` and `semanticType`. `analyticalType` can
13+
#' only be one of "measure" or "dimension". `semanticType` can only be one of
14+
#' "quantitative", "temporal", "nominal" or "ordinal". For example:
15+
#' \code{list(
16+
#' "gender" = list(analyticalType = "dimension", semanticType = "nominal"),
17+
#' "age" = list(analyticalType = "measure", semanticType = "quantitative")
18+
#' )}
19+
#' @param visConfig An optional config string to reproduce your chart. You can copy the string by clicking "export config" button on the GWalkR interface.
20+
#'
21+
#' @return An \code{htmlwidget} object that can be rendered in R environments
922
#'
1023
#' @examples
11-
#' \dontrun{
1224
#' data(mtcars)
1325
#' gwalkr(mtcars)
14-
#' }
1526
#'
1627
#' @export
17-
gwalkr <- function(data, lang = "en") {
28+
gwalkr <- function(data, lang = "en", columnSpecs = list(), visConfig = NULL) {
1829
if (!is.data.frame(data)) stop("data must be a data frame")
1930
lang <- match.arg(lang, choices = c("en", "ja", "zh"))
2031

32+
rawFields <- raw_fields(data, columnSpecs)
33+
colnames(data) <- sapply(colnames(data), fname_encode)
2134
# forward options using x
2235
x = list(
23-
dataSource = jsonlite::toJSON(data, pretty=TRUE),
24-
rawFields = raw_fields(data),
36+
dataSource = jsonlite::toJSON(data),
37+
rawFields = rawFields,
2538
i18nLang = lang,
26-
hideDataSourceConfig = TRUE
39+
hideDataSourceConfig = TRUE,
40+
visSpec = visConfig
2741
)
2842

2943
# create widget
@@ -40,6 +54,8 @@ gwalkr <- function(data, lang = "en") {
4054
#'
4155
#' Output and render functions for using gwalkr within Shiny
4256
#' applications and interactive Rmd documents.
57+
#'
58+
#' @import shiny
4359
#'
4460
#' @param outputId output variable to read from
4561
#' @param width,height Must be a valid CSS unit (like \code{'100\%'},
@@ -53,7 +69,27 @@ gwalkr <- function(data, lang = "en") {
5369
#' @name gwalkr-shiny
5470
#'
5571
#' @export
56-
gwalkrOutput <- function(outputId, width = '100%', height = '400px'){
72+
#' @examples # !formatR
73+
#' library(GWalkR)
74+
#' library(shiny)
75+
#' data(mtcars)
76+
#' app <- shinyApp(
77+
#' ui = fluidPage(
78+
#' titlePanel("Explore the data here: "),
79+
#' gwalkrOutput("mygraph")
80+
#' ),
81+
#' server = function(input, output, session) {
82+
#' output$mygraph = renderGwalkr(
83+
#' gwalkr(mtcars)
84+
#' )
85+
#' }
86+
#' )
87+
#' \donttest{if (interactive()) app}
88+
#' @return \itemize{
89+
#' \item \code{gwalkrOutput}: A \code{shinyWidgetOutput} object for the root HTML element.
90+
#' \item \code{renderGwalkr}: A server-side function to help Shiny display the GWalkR visualization.
91+
#' }
92+
gwalkrOutput <- function(outputId, width = '100%', height = '100%'){
5793
htmlwidgets::shinyWidgetOutput(outputId, 'gwalkr', width, height, package = 'GWalkR')
5894
}
5995

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[English](README.md) | [中文](./docs/README.zh.md)
1+
[English](README.md) | [中文](docs/README.zh.md)
22

33
<img src="docs/img/hex_logo.png" align="right" alt="logo" width="120" height = "139" style = "border: none; float: right;">
44

@@ -7,7 +7,7 @@
77
![](https://img.shields.io/github/actions/workflow/status/kanaries/GWalkR/web-app-build.yml?style=flat-square)
88
![](https://img.shields.io/github/license/kanaries/GWalkR?style=flat-square)
99
[![](https://img.shields.io/badge/twitter-kanaries_data-03A9F4?style=flat-square&logo=twitter)](https://twitter.com/kanaries_data)
10-
[![](https://img.shields.io/discord/987366424634884096?color=%237289da&label=Discord&logo=discord&logoColor=white&style=flat-square)](https://discord.gg/WWHraZ8SeV)
10+
[![](https://img.shields.io/discord/987366424634884096?color=%237289da&label=Discord&logo=discord&logoColor=white&style=flat-square)](https://discord.com/invite/WWHraZ8SeV)
1111

1212
Start Exploratory Data Analysis (EDA) in R with a Single Line of Code!
1313
[GWalkR](https://github.com/Kanaries/GWalkR) is an interactive Exploratory Data Analysis (EDA) Tool in R.
@@ -27,12 +27,12 @@ It can simplify your R data analysis and data visualization workflow, by turning
2727
If you have `devtools` installed in R, you can run the following R code to install.
2828

2929
```R
30-
devtools::install_url("https://kanaries-app.s3.ap-northeast-1.amazonaws.com/oss/gwalkr/GWalkR_0.1.0.tar.gz")
30+
devtools::install_url("https://kanaries-app.s3.ap-northeast-1.amazonaws.com/oss/gwalkr/GWalkR_latest.tar.gz")
3131
```
3232

3333
#### Through Package Archive File (.tar.gz)
3434

35-
Alternatively, download the package archive file `GWalkR_0.1.0.tar.gz` from [this link](https://kanaries-app.s3.ap-northeast-1.amazonaws.com/oss/gwalkr/GWalkR_0.1.0.tar.gz).
35+
Alternatively, download the package archive file `GWalkR_latest.tar.gz` from [this link](https://kanaries-app.s3.ap-northeast-1.amazonaws.com/oss/gwalkr/GWalkR_latest.tar.gz).
3636
Open R Studio, click "Install" in the "Packages" window, and select "Package Archive File (.tgz; .tar.gz)" in the "Install from". Then, select the archive in your file system and click "Install".
3737

3838
#### Through CRAN

docs/README.zh.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
![](https://img.shields.io/github/actions/workflow/status/kanaries/GWalkR/web-app-build.yml?style=flat-square)
66
![](https://img.shields.io/github/license/kanaries/GWalkR?style=flat-square)
77
[![](https://img.shields.io/badge/twitter-kanaries_data-03A9F4?style=flat-square&logo=twitter)](https://twitter.com/kanaries_data)
8-
[![](https://img.shields.io/discord/987366424634884096?color=%237289da&label=Discord&logo=discord&logoColor=white&style=flat-square)](https://discord.gg/WWHraZ8SeV)
8+
[![](https://img.shields.io/discord/987366424634884096?color=%237289da&label=Discord&logo=discord&logoColor=white&style=flat-square)](https://discord.com/invite/WWHraZ8SeV)
99

1010
一行代码,开启您在R中的数据探索之旅!
1111

@@ -27,12 +27,12 @@
2727
如果您已在R中安装了`devtools`,您可以在脚本中运行以下R代码来下载。
2828

2929
```R
30-
devtools::install_url("https://kanaries-app.s3.ap-northeast-1.amazonaws.com/oss/gwalkr/GWalkR_0.1.0.tar.gz")
30+
devtools::install_url("https://kanaries-app.s3.ap-northeast-1.amazonaws.com/oss/gwalkr/GWalkR_latest.tar.gz")
3131
```
3232

3333
#### 通过下载 .tar.gz 文件包安装
3434

35-
或者,从[这个链接](https://kanaries-app.s3.ap-northeast-1.amazonaws.com/oss/gwalkr/GWalkR_0.1.0.tar.gz)中下载包 GWalkR_0.1.0.tar.gz。
35+
或者,从[这个链接](https://kanaries-app.s3.ap-northeast-1.amazonaws.com/oss/gwalkr/GWalkR_latest.tar.gz)中下载包 GWalkR_latest.tar.gz。
3636
打开 R Studio,点击 "Packages" 窗口中的 "Install",然后在 "Install from" 中选择 "Package Archive File (.tgz; .tar.gz)"。然后,选择您的文件系统中的下载好的包,最后点击"Install"。
3737

3838
#### 通过 CRAN 安装

inst/htmlwidgets/gwalkr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ dependencies:
44
src: htmlwidgets/lib/gwalkr
55
script:
66
- gwalkr-app.iife.js
7+
stylesheet:
78
- style.css
8-
- vite.svg

man/gwalkr-shiny.Rd

Lines changed: 25 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/gwalkr.Rd

Lines changed: 16 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web_app/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html lang="en" class="dark">
33
<head>
44
<meta charset="UTF-8" />
55
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>Vite + React + TS</title>
7+
<title>GWalkR App</title>
88
</head>
99
<body>
1010
<div id="rwalker-app"></div>

0 commit comments

Comments
 (0)