g2inr / g2r Goto Github PK
View Code? Open in Web Editor NEWexperiments with R and g2
License: Other
experiments with R and g2
License: Other
jsonlite
is an amazing and well-built JSON converter with a focus on reliable conversion back and forth from R structures <-> JSON equivalents. This focus on two-way conversion means that unquoted JavaScript
is not supported. I like the idea of using noquote
to indicate JavaScript
variables, but I struggle with a clean way of piggybacking on top of jsonlite
to add this functionality. See ugly hack below.
# gosh this is ugly and I'm sure highly worst practice
asJSON <- jsonlite:::asJSON
setMethod("asJSON", "ANY", function(x, force = FALSE, ...) {
if (inherits(x, "noquote")) {
return(x)
}
if (isS4(x) && !is(x, "classRepresentation")) {
if (isTRUE(force)) {
return(asJSON(attributes(x), force = force, ...))
} else {
stop("No method for S4 class:", class(x))
}
} else if (length(class(x)) > 1) {
# If an object has multiple classes, we recursively try the next class. This is
# S3 style dispatching that doesn't work by default for formal method definitions
# There should be a more native way to accomplish this
return(asJSON(structure(x, class = class(x)[-1]), force = force, ...))
} else if (isTRUE(force) && existsMethod("asJSON", class(unclass(x)))) {
# As a last resort we can force encoding using the unclassed object
return(asJSON(unclass(x), force = force, ...))
} else if (isTRUE(force)) {
return(asJSON(NULL))
warning("No method asJSON S3 class: ", class(x))
} else {
# If even that doesn't work, we give up.
stop("No method asJSON S3 class: ", class(x))
}
})
assignInNamespace("asJSON", asJSON, ns="jsonlite")
rm(asJSON, envir = .GlobalEnv)
A very similar problem occurs with htmltools
and tags in the React/JSX ecosystem. See rstudio/htmltools#72 as a proposed workaround. Unfortunately, there has been no communication from RStudio on the viability of this approach. I certainly don't want to manage a fork for this functionality.
Some code to start working through the integration. This is ugly and very hacky. Of course the ultimate objective is to write a full-featured htmlwidget
that is usable for an R user with no knowledge of JavaScript.
See sketch
Hello hello, I wanted to say I have been working on a similar project over at nteetor/golly. Someone just pointed me toward this project.
Perhaps there is a way we can combine forces? I look forward to hearing back from you.
I could find any difference in g2 and Vega on internet. So my question is why g2 and will g2 be supported long enough by js community that we can use it.
I mean Vega is quite time tested and famous library it's easier to find support for it and it's easier to just form ggvis on GitHub.
Why g2? Please do reply
I chose g2r
to start the project, but I am by no means wedded to the name? Are there other suggestions?
I somehow completely missed the documentation on spec-based chart creation in g2
https://antv.alipay.com/zh-cn/g2/3.x/api/options.html. This should greatly simplify #1 and possibly helps make a decision on #2. @mdequeljoe, I think our best option will be to pursue this route.
Hi,
Sorry, this is not directly related to the R implementation, but do you know if there is an english version of the API documentation ? Beside a simple tutorial I've only managed to find one in chinese.
Thanks !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.