nachocab / clickme

An R package to create interactive plots
257 stars 44 forks source link

Embedding in rNotebook/knitr using R Markdown in RStudio #39

Open royfrancis opened 11 years ago

royfrancis commented 11 years ago

Hi, What is the best way to embed the chart/plot into an rNotebook/knitr rather than open as a new tab?

library(clickme)
c1<-clickme(points, 1:10)

Is there something like
print(c1)
or
c1$print("chart")

Thanks, Roy

nachocab commented 11 years ago

Hey Roy, you can just do clickme(points, 1:10)$iframe()

On Saturday, July 27, 2013, royfrancis wrote:

Hi, What is the best way to embed the chart/plot into an rNotebook/knitr rather than open as a new tab?

library(clickme)c1<-clickme(points, 1:10) Is there something likeprint(c1)orc1$print("chart")

Thanks, Roy

— Reply to this email directly or view it on GitHubhttps://github.com/nachocab/clickme/issues/39 .

royfrancis commented 11 years ago

Well.. Something is happening, but it still doesn't produce the graph. It produces an empty rectangle. Maybe it doesn't point to the right path. I have attached the output I get as an image. I have tried to open this in a browser and I get an empty grey box.

I am doing this in RStudio and an R Markdown. Here is how my code looks like:

library(clickme)

c1<-clickme(points, 1:10)
c1$iframe() 

im1

nachocab commented 11 years ago

Hey Roy, That's weird. I'm not very familiar with RStudio, so I don't know why it's giving you that error. If you open /html_preview/temp-Points.html in your browser, it should work. I'll investigate once I get back to Boston (I'm traveling right now). Let me know how it went.

ramnathv commented 11 years ago

I can confirm that it does NOT work with R Markdown, and I get a same blank screen. Digging deeper, here is what I realized. Calling c1$iframe() adds the following HTML to the output

<iframe width = "1000" height = "724" src="temp-Points.html"> </iframe>

But the temp-Points.html file is still located at

file://localhost/Library/Frameworks/R.framework/Versions/3.0/Resources/library/clickme/output/temp-Points.html

So, your iframe method will have to do more than just add the iframe to the output.

I tested it from the R console, and it leads to the same error.

nachocab commented 11 years ago

Good catch.Thanks for the feedback. One option is to set the directory explicitly:

clickme(points, 1:10, dir = getwd())$iframe()

By default dir is set to getOption("clickme_output_path"). I'm not sure I should change the default to getwd(), because that would mean creating the temp-Points.html file and the clickme_assets in the current path.

Also, I just pushed a new commit to fix the frameborder and the height scroll. You can update with

library(devtools)
install_github("clickme", "nachocab")
library(clickme")
royfrancis commented 11 years ago

Ok. I just tried it out and it works. Now the c1$iframe() also works. It works in the RStudio preview and in browser. But when I export to Rpubs, the clickme plot give an error like so

AccessDeniedAccess Denied364B39C1DF230F7BtbwaOKfBHcNpzjuMcBixVHEcLkqEjsNqZTN8xMdi66c9SYtRGPHYAbkUqPKuiMzx

But, everything else (like other plots and content) gets published.

ramnathv commented 11 years ago

The clickme js and css assets probably are still linked to a folder on your computer, which is why they are not showing up on RPubs.

royfrancis commented 11 years ago

Ah yes. We probably need something like include_assets in rCharts..

timcameron commented 10 years ago

I still can't get this to work even after including the dir = getwd(). I can see the "temp-points.html" get created in my directory but it won't render in RMarkdown - see image.

capture

nachocab commented 10 years ago

It's probably because you don't have coffeescript install, you can get it at http://coffeescript.org/

On Sun, Sep 7, 2014 at 4:58 AM, TC notifications@github.com wrote:

I still can't get this to work even after including the dir = getwd(). I can see the "temp-points.html" get created in my directory but it won't render in RMarkdown - see image.

[image: capture] https://cloud.githubusercontent.com/assets/4188986/4177985/f80317be-366c-11e4-9a73-294f1e51761c.PNG

— Reply to this email directly or view it on GitHub https://github.com/nachocab/clickme/issues/39#issuecomment-54741310.