Open timelyportfolio opened 11 years ago
I like your idea and thanks for taking the initiative. However, I would prefer to use datasets built into R (preferably base R), so that users dont get distracted by the data preparation steps. I want users to be able to take a data frame and plot it as they would, using lattice or ggplot2.
I just pushed a new version to github that includes a create_chart
function that takes a .R
file with an example, and converts it into an example page with the source code (simple layout). I would like you to try it and let me know how it works. Here is how it works. Assume, you save the following code to example_lotr.R
jsondata = data.frame(
c("The Fellowship of the Ring","The Two Towers","The Return of the King","The Hobbit"),
c(871530000, 926047000, 1119929000, 949541000)
)
colnames(jsondata) <- c("movie","gross")
p6 <- rPlot(gross ~ movie, data = jsondata, type = "bar", color=list(const="darkgreen"))
p6$set(title = "Lord of the Rings Box Office Gross")
p6
You can generate an example page using the code below. Note that just typing mychart
automatically calls the show method, the default for which has not been changed to static = T
.
mychart = create_chart('example_lotr.R')
mychart
Publishing your chart now is even simpler. Just do
mychart$publish('LOTR Box Office Gross')
rCharts will automatically switch to serving all assets from the CDN so that it works online. Right now the title does not show up, but it is only a matter of tweaking the layout to get it right. You can check the layouts out in inst/rChart.html
and inst/rChart2.html
.
Let me know how it works for you, and any feedback you have.
Great, I will experiment with the new functionality. It should be very helpful for automatically publishing examples. I am excited.
Since I was already so deep in replicating the polycharts demo examples, I went ahead and completed for all of them with the exception of the interactive and pies ( did but don't work due to #3 ) and updated the issue above. Unfortunately, I think users will at some point almost always be confronted with translating r to js data. I wish I had a fairly complete and robust set of examples that I could learn from when I started this quest. These present a small set. Thanks for all that you have done to hide the difficult translation.
I am most interested in recreating the ggplot2 and lattice examples as we discussed in #31 . For R users, I think this would be incredibly beneficial, and for you, I think the tests will be very instructive.
Wow. That is terrific. Here is what I would recommend that you do. Maintain each example you create in a standalone R file. Make sure that it is truly standalone, in the sense that a user should be able to open a fresh R session and just source the file to view the chart.
Once I finalize the layouts, it should be easy to run create_chart
to convert them into full fledged example pages. I plan to add disqus comments as well as social sharing snippets. I might go a little slow on this, because I want to nail the layout right before showing it to users.
Thanks again for all your hard work.
I will do as suggested with the standalone examples and follow the same process going forward.
now, I really want to focus on NVD3 and Rickshaw, since the license is more open. polycharts grammar is just irresistible given my love of lattice.
Great. I have some NVD3 examples too, which I will add to the mix in a bit. Rickshaw implementation is not complete. Moreover, legends and axes are more complicated in Rickshaw since it treats everything as a separate entity. MorrisJS on the other hand is really simple, and the spec structure is not nested, which means that any spec on their API page, can be set using the addParams
or set
method! MorrisJS code is also super clean, written in coffeescript and hence actually extensible.
Did you try create_chart
and the publish
method? Let me know. I might refactor these methods outside of rCharts
so that more packages can use it (e.g. clickme).
This discussion on shiny google-groups seems very relevant. I think I am going to accelerate the sharing of examples.
I think focusing on Polychart and NVD3 would be a prudent choice, since these two libraries seem to have the best interactive capabilities. I can ask Thomas to focus on more examples with Highchart.
Just got of a lunch meeting and starting to experiment again.
I have started two new issues
@ramnathv I hope this is close to what you expected https://github.com/timelyportfolio/rCharts_polycharts_standalone/.
I glanced through it and it looks good. I will go over in more detail and add my comments.
Meanwhile, I just cooked up a runExample
function similar to runGitHub
in Shiny. It seems to work fine for me. Can you test it? If it works well, I can roll it back into rCharts, so that instructions on your README.md can be simpler.
runExample <- function(repo, username, filename, ref = 'master'){
require(downloader)
tf <- tempfile(pattern = '*.R')
url <- sprintf('https://raw.github.com/%s/%s/%s/%s',
username, repo, ref, filename)
download(url, tf)
mychart = rCharts::create_chart(tf)
return(mychart)
}
runExample(
username = 'timelyportfolio',
repo = 'rCharts_polycharts_standalone',
filename = 'area_osshare.R'
)
Just shut down my computer before I saw this. Code looks like it will work. I will test in the morning.
Kent
On Apr 23, 2013, at 9:23 PM, Ramnath Vaidyanathan notifications@github.com wrote:
I glanced through it and it looks good. I will go over in more detail and add my comments.
Meanwhile, I just cooked up a runExample function similar to runGitHub in Shiny. It seems to work fine for me. Can you test it? If it works well, I can roll it back into rCharts, so that instructions on your README.md can be simpler.
runExample <- function(repo, username, filename, ref = 'master'){ require(downloader) tf <- tempfile(pattern = '*.R') url <- sprintf('https://raw.github.com/%s/%s/%s/%s', username, repo, ref, filename) download(url, tf) mychart = rCharts::create_chart(tf) return(mychart) }
runExample( username = 'timelyportfolio', repo = 'rCharts_polycharts_standalone', filename = 'area_osshare.R' ) — Reply to this email directly or view it on GitHub.
on my windows 7, I needed
tf <- tempfile(pattern = '.R')
instead of *.R
Great. I will make the change. But it works if you make that change right?
Yes it works with that change.
Kent
On Apr 24, 2013, at 10:55 AM, Ramnath Vaidyanathan notifications@github.com wrote:
Great. I will make the change. But it works if you make that change right?
— Reply to this email directly or view it on GitHub.
I reformatted the repo using formatR.
I coded up a quick set of functions to create a gallery from a directory containing example files. It is still preliminary, but it would be nice if you could test it. Update your version of rCharts and source the functions below into your
workspace and run make_example_pages(".", cdn = T)
from your example directory. The resulting pages should look like this. I plan to make a few enhancements to the page, which requires the example files to include custom metadata as comment. I will post more on this. Finally, I want to integrate social sharing buttons as well as disqus comments so that users can initiate a discussion.
make_example_pages <- function(exDir, htmlDir = 'gallery'){
rFiles = dir(exDir, pattern = ".R")
sidebar = get_sidebar(exDir)
if (!file.exists(htmlDir)) dir.create(htmlDir)
invisible(lapply(rFiles, make_example_page, sidebar, htmlDir))
}
get_sidebar <- function(exDir){
rFiles = dir(exDir, pattern = "*.R")
menu = lapply(rFiles, function(rFile){
filename = tools:::file_path_sans_ext(basename(rFile))
c(title = filename, href = sprintf("%s.html", filename))
})
list(menu = menu)
}
make_example_page <- function(rFile, sidebar, htmlDir){
myexample = rCharts::create_chart(rFile)
filename = tools:::file_path_sans_ext(basename(rFile))
active = which(lapply(sidebar$menu, '[[', 'title') == filename)
sidebar$menu[[active]] = c(sidebar$menu[[active]], class = 'active')
myexample$field('tObj', sidebar)
htmlFile = sprintf('%s/%s.html', htmlDir, filename)
myexample$save(destfile = htmlFile, cdn = T)
}
more I play with the others, the more I realize how nice polycharts is. of course, it is the only one with a paid license and the least interactivity.
Yes. But it is not terribly expensive, as you can see here http://polychart.com/js/license. The developers have obviously put in a lot of thought, and Polycharts is probably the closes to delivering the reusable chart experience. NVD3 is slick, but the documentation is non-existent and the only way to figure things out is to dig into the source code.
I am close to implementing faceting in NVD3. So, once that happens, I believe we can replicate some of Polychart's functionality in NVD3.
I have no problems with the price, but I know some won't use it even if it is only $1. Think I'll have a go at Morris now.
just realized I never tried your functions above. I just ran on all the lattice conversions. Works great http://timelyportfolio.github.io/rCharts_lattice_book/polycharts_versions/gallery/figure1_01.html.
You can also see in the repo where I grab the lattice code from the site. Unfortunately, it is not as well structured as it first seemed.
I took a quick look and it seems great. The sidebar could use some tweaking. I am thinking a collapsible sidebar by chapter
What would also be very nice is to add the ability to specify a .rmd or .md as a parameter to add to the beginning.
Another good test would be to replicate the examples provided in the libraries. I started on polycharts.
polychart.js examples in rCharts
Dow Jones (Simple Line)
Dow Jones (Auto Updating)
Browser Shares (Multiple Lines)
Operating Systems Shares Area
Iris Flower Scatter Plot
Bubble Chart (Animated)
LOTR Box Office Gross
Histogram of Heights (Histogram)
Highest Paid Athletes (Flipped)
Sales Funnel (Stacking)
Department Salaries (Dodging)
Favourite Pets (Simple)
Favourite Pets (Animating)
Volunteer Requirements (Facet)
Boxplot
Iris Flower Tile Plot (Tile, Binning)
Population (Interactive)
If we can create this one, we know we can do almost anything
Iris Flower Facetted Plot