Skip to content

Commit 10cbf1e

Browse files
Merge pull request #1 from Bruceshark/main
init GWalkR
2 parents 5ec9a37 + edd5772 commit 10cbf1e

26 files changed

+4981
-2
lines changed

.Rbuildignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
^GWalkR\.Rproj$
2+
^\.Rproj\.user$
3+
^web_app
4+
^graphic-walker
5+
^GWalkR.Rcheck
6+
^\.vscode$
7+
^LICENSE$

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,10 @@ po/*~
4747

4848
# RStudio Connect folder
4949
rsconnect/
50+
51+
.DS_Store
52+
node_modules
53+
54+
.vscode/
55+
56+
inst/htmlwidgets/lib/gwalkr

DESCRIPTION

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Package: GWalkR
2+
Title: Interactive Exploratory Data Analysis Tool in R
3+
Version: 0.1.0
4+
Authors@R: c(
5+
person("Yue", "Yu", , "[email protected]", role = c("aut", "cre"),
6+
comment = c(ORCID = "0000-0002-9302-0793")),
7+
person("Kanaries Data Inc.", role = c("cph", "fnd")))
8+
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.
10+
License: Apache License (>= 2)
11+
Encoding: UTF-8
12+
Roxygen: list(markdown = TRUE)
13+
RoxygenNote: 7.2.3
14+
URL: https://github.com/Kanaries/GWalkR/
15+
Imports:
16+
htmlwidgets,
17+
jsonlite,

GWalkR.Rproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Version: 1.0
2+
3+
RestoreWorkspace: No
4+
SaveWorkspace: No
5+
AlwaysSaveHistory: Default
6+
7+
EnableCodeIndexing: Yes
8+
Encoding: UTF-8
9+
10+
AutoAppendNewline: Yes
11+
StripTrailingWhitespace: Yes
12+
LineEndingConversion: Posix
13+
14+
BuildType: Package
15+
PackageUseDevtools: Yes
16+
PackageInstallArgs: --no-multiarch --with-keep.source
17+
PackageRoxygenize: rd,collate,namespace

NAMESPACE

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export(gwalkr)
4+
export(gwalkrOutput)
5+
export(renderGwalkr)
6+
import(htmlwidgets)

R/data_parser.R

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
raw_fields <- function(df) {
2+
cols <- colnames(df)
3+
props <- lapply(seq_along(cols), function(i) {
4+
infer_prop(cols[i], i, df)
5+
})
6+
return(props)
7+
}
8+
9+
infer_prop <- function(col, i = NULL, df) {
10+
s <- df[[col]]
11+
semantic_type <- infer_semantic(s)
12+
analytic_type <- infer_analytic(s)
13+
prop <- list(
14+
fid = col,
15+
name = col,
16+
semanticType = semantic_type,
17+
analyticType = analytic_type
18+
)
19+
return(prop)
20+
}
21+
22+
infer_semantic <- function(s) {
23+
v_cnt <- length(unique(s))
24+
kind <- class(s)
25+
if (any(sapply(c('numeric', 'integer'), inherits, x = s)) & v_cnt > 16) {
26+
return('quantitative')
27+
} else if (any(sapply(c('POSIXct', 'POSIXlt', 'Date'), inherits, x = s))) {
28+
return('temporal')
29+
} else if (inherits(s, 'ordered')) {
30+
return('ordinal')
31+
} else {
32+
return('nominal')
33+
}
34+
}
35+
36+
infer_analytic <- function(s) {
37+
v_cnt <- length(unique(s))
38+
kind <- class(s)
39+
if ((inherits(s, 'numeric')) | (inherits(s, 'integer') & v_cnt > 16)) {
40+
return('measure')
41+
} else {
42+
return('dimension')
43+
}
44+
}

R/gwalkr.R

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#' Create GWalkR Interface in "Viewer"
2+
#'
3+
#' 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.
4+
#'
5+
#' @import htmlwidgets
6+
#'
7+
#' @param data A data frame to be visualized in the GWalkR. The data frame should not be empty.
8+
#' @param lang A character string specifying the language for the widget. Possible values are "en" (default), "ja", "zh".
9+
#'
10+
#' @examples
11+
#' \dontrun{
12+
#' data(mtcars)
13+
#' gwalkr(mtcars)
14+
#' }
15+
#'
16+
#' @export
17+
gwalkr <- function(data, lang = "en") {
18+
if (!is.data.frame(data)) stop("data must be a data frame")
19+
lang <- match.arg(lang, choices = c("en", "ja", "zh"))
20+
21+
# forward options using x
22+
x = list(
23+
dataSource = jsonlite::toJSON(data, pretty=TRUE),
24+
rawFields = raw_fields(data),
25+
i18nLang = lang
26+
)
27+
28+
# create widget
29+
htmlwidgets::createWidget(
30+
name = 'gwalkr',
31+
x,
32+
package = 'GWalkR'
33+
)
34+
}
35+
36+
#' Shiny bindings for gwalkr
37+
#'
38+
#' Output and render functions for using gwalkr within Shiny
39+
#' applications and interactive Rmd documents.
40+
#'
41+
#' @param outputId output variable to read from
42+
#' @param width,height Must be a valid CSS unit (like \code{'100\%'},
43+
#' \code{'400px'}, \code{'auto'}) or a number, which will be coerced to a
44+
#' string and have \code{'px'} appended.
45+
#' @param expr An expression that generates a gwalkr
46+
#' @param env The environment in which to evaluate \code{expr}.
47+
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
48+
#' is useful if you want to save an expression in a variable.
49+
#'
50+
#' @name gwalkr-shiny
51+
#'
52+
#' @export
53+
gwalkrOutput <- function(outputId, width = '100%', height = '400px'){
54+
htmlwidgets::shinyWidgetOutput(outputId, 'gwalkr', width, height, package = 'GWalkR')
55+
}
56+
57+
#' @rdname gwalkr-shiny
58+
#' @export
59+
renderGwalkr <- function(expr, env = parent.frame(), quoted = FALSE) {
60+
if (!quoted) { expr <- substitute(expr) } # force quoted
61+
htmlwidgets::shinyRenderWidget(expr, gwalkrOutput, env, quoted = TRUE)
62+
}

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,43 @@
1-
# GWalkR
2-
R binding of graphic-walker, use table style drag and drop UI interface to build visualization in R.
1+
# GWalkR: Your One-Stop R Package for Exploratory Data Analysis with Visualization
2+
3+
Start Exploratory Data Analysis (EDA) in R with a Single Line of Code!
4+
[GWalkR](https://github.com/Kanaries/GWalkR) is an interactive Exploratory Data Analysis (EDA) Tool in R.
5+
It integrates the htmlwidgets with [Graphic Walker](https://github.com/Kanaries/graphic-walker).
6+
It can can simplify your R data analysis and data visualization workflow, by turning your data frame into a Tableau-style User Interface for visual exploration.
7+
8+
<img width="1437" alt="image" src="https://github.com/Bruceshark/GWalkR/assets/33870780/26967dda-57c0-4abd-823c-63037c8f5168">
9+
10+
11+
## Getting Started
12+
13+
### Setup GWalkR
14+
15+
#### Through Package Archive File (.tar.gz)
16+
17+
First, download the package archive file `GWalkR_0.1.0.tar.gz` from the Github release.
18+
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".
19+
20+
#### Through Running R Script
21+
22+
Alternatively, you can run the following R code in your script to download without a lot of clicking.
23+
24+
```R
25+
url <- "https://github.com/Bruceshark/GWalkR/releases/download/preview/GWalkR_0.1.0.tar.gz"
26+
destfile <- "GWalkR_0.1.0.tar.gz"
27+
download.file(url, destfile)
28+
install.packages(destfile, repos = NULL, type = "source")
29+
```
30+
31+
#### Through CRAN
32+
33+
To be supported soon. Stay tuned!
34+
35+
36+
### Start Your Data Exploration in a Single Line of Code
37+
38+
```R
39+
library(GWalkR)
40+
data(iris)
41+
gwalkr(iris)
42+
```
43+

inst/htmlwidgets/gwalkr.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
HTMLWidgets.widget({
2+
3+
name: 'gwalkr',
4+
5+
type: 'output',
6+
7+
factory: function(el, width, height) {
8+
9+
// TODO: define shared variables for this instance
10+
11+
return {
12+
13+
renderValue: function(x) {
14+
15+
GWalkRApp(x, el.id);
16+
17+
},
18+
19+
resize: function(width, height) {
20+
21+
// TODO: code to re-render the widget with a new size
22+
23+
}
24+
25+
};
26+
}
27+
});

inst/htmlwidgets/gwalkr.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
dependencies:
2+
- name: gwalkr
3+
version: 1.0.0
4+
src: htmlwidgets/lib/gwalkr
5+
script:
6+
- gwalkr-app.iife.js
7+
- style.css
8+
- vite.svg

0 commit comments

Comments
 (0)