Open jrowen opened 10 years ago
If you are using it with pandoc
and selfcontained = TRUE
, a better option might be to just use
a$show('inline', include_assets = TRUE)
This way pandoc
will automatically pick up the dependencies.
Let me know if this works. I will push a fix for the cdn = TRUE
case as well, but this should work for now.
With cdn = FALSE
, I'm seeing the error below
pandoc.exe: Failed to retrieve C:/Users/jrowen/Documents/R/win-library/3.1/rCharts/libraries/highcharts/js/jquery-1.9.1.min.js
InvalidUrlException "C:/Users/jrowen/Documents/R/win-library/3.1/rCharts/libraries/highcharts/js/jquery-1.9.1.min.js" "Invalid scheme"
Error: pandoc document conversion failed with error 61
I'm using the preview version of RStudio to create the document. Below are the relevant lines from the md
file.
<script type='text/javascript' src=C:/Users/jrowen/Documents/R/win-library/3.1/rCharts/libraries/highcharts/js/jquery-1.9.1.min.js></script>
<script type='text/javascript' src=C:/Users/jrowen/Documents/R/win-library/3.1/rCharts/libraries/highcharts/js/highcharts.js></script>
<script type='text/javascript' src=C:/Users/jrowen/Documents/R/win-library/3.1/rCharts/libraries/highcharts/js/highcharts-more.js></script>
<script type='text/javascript' src=C:/Users/jrowen/Documents/R/win-library/3.1/rCharts/libraries/highcharts/js/exporting.js></script>
Ah. I should have guessed that. Let me push the fix for cdn = TRUE
. I will try to get it done this week.
I'm running into the same error when adding controls to a plot, but I'm assuming the same logic is used to add the script
tags in all cases.
Even after manually correcting the script path, I'm seeing the controls but not the plot, so if you have any suggestions, I'd appreciate it. Here's a sample rmd
file I'm using.
---
title: "rCharts"
output: html_document
---
```{r rcht, message=FALSE, echo=FALSE, results='asis'}
library(rCharts)
n1 <- rPlot(mpg ~ wt, data = mtcars, color = "gear", type = "point")
n1$addControls("x", value = "wt", values = names(mtcars))
n1$addControls("y", value = "wt", values = names(mtcars))
n1$addControls("color", value = "gear", values = names(mtcars))
n1$addParams(height=600, width="80%")
n1$show('inline', include_assets = TRUE, cdn = TRUE)
A little more background for the requests. I think a better way to accomplish this is to create a `shiny`app, but I'm running into situations where I need to share analysis via email. I've found that the standalone html is a good mechanism, and the interactivity of `rCharts` is really useful. Thanks for the assistance.
@jrowen I have NOT yet optimized rCharts
for the new rmarkdown
workflow. Pandoc is very strict about how it views dependencies, and that makes life difficult. I am not sure if I will be able to come up with a quick solution to this problem, but I will be working on it and will update you.
I tried your code. The chart with controls use a slightly different mechanism and haven't been optimized for the rmarkdown
workflow. However, the following works for me with rmarkdown
.
---
title: "rCharts"
output: html_document
---
```{r rcht, message=FALSE, echo=FALSE, results='asis'}
library(rCharts)
n1 <- rPlot(mpg ~ wt, data = mtcars, color = "gear", type = "point")
n1$show('inline', include_assets = TRUE, cdn = F)
The charts with control code worked for me with an iframe option: n1$save as html and iframe of that file.
Does it work when you have the selfcontained
option turned on in rmarkdown
?
I wasn't able to get inline
to work, as pandoc appears to ignore the iframe
tag leaving the external file reference in place.
Another option might be n1$show('iframesrc', cdn = TRUE)
. Although this would not be completely self-contained
, it would include all of the local data within the file and only require an internet connection to access the external script and stylesheets.
I've been able to get this to work by editing the resulting html file to prepend http:
to the //ramnathv.github.io/rCharts/libraries/widgets/polycharts/js/polychart2.standalone.js
path and increasing the iframe.rChart
height parameter in the style
.
I'm assuming that the cdn
fix will also correct the path for the widgets scripts. Would it also be possible to parameterize the <style>iframe.rChart{ width: 100%; height: 400px;}</style>
tag within the iframesrc
result?
title: "tmp" author: "tmp" date: "Wednesday, August 13, 2014"
library(rCharts)
n1 <- rPlot(mpg ~ wt, data = mtcars, color = "gear", type = "point")
n1$addControls("x", value = "wt", values = names(mtcars))
n1$addControls("y", value = "wt", values = names(mtcars))
n1$addControls("color", value = "gear", values = names(mtcars))
n1$save("abc.html",standalone=TRUE)
@patilv I think your approach works if the desired output is a single rChart. In this situation, I'm looking to include an rChart within a larger html document, and therefore need to capture the output using show()
.
@jrowen , I am not sure of your objective but I would think the approach would could handle multiple charts. As an example, the following Rmd with two rCharts also works for me (offline).
title: "tmp" author: "tmp" date: "Wednesday, August 13, 2014" output: html_document
library(rCharts)
n1 <- rPlot(mpg ~ wt, data = mtcars, color = "gear", type = "point")
n1$addControls("x", value = "wt", values = names(mtcars))
n1$addControls("y", value = "wt", values = names(mtcars))
n1$addControls("color", value = "gear", values = names(mtcars))
n1$save("abc.html",standalone=TRUE)
<iframe src="abc.html" width="1100" height="600"></iframe>
n2 <- nPlot(mpg ~ wt, data = mtcars, group = "gear", type = "scatterChart")
n2$addControls("x", value = "wt", values = names(mtcars))
n2$addControls("group", value = "gear", values = names(mtcars))
n2$save("def.html",standalone=TRUE)
<iframe src="def.html" width="1100" height="600"></iframe>
Hi, Using this Rcharts script
library(rCharts)
n1 <- rPlot(mpg ~ wt, data = mtcars, color = "gear", type = "point")
n1$show('iframesrc', cdn = TRUE)
into a iosslide presentation using RMarkdown, nothing appear :/
---
title: "presentation"
author: "bla"
date: "22/10/2014"
output:
ioslides_presentation:
highlight: pygments
css: slides.css
runtime: shiny
widescreen: yes
---
You need to open the presentation in a local webserver, either using the servr
package or python -m SimpleHTTPServer
.
Code works - link of deployed shiny app: https://patilv.shinyapps.io/rchartsmarkdownissue/rchartsmarkdownissue.Rmd#1
Thanks @patilv for checking this. I will wait for @reyman to confirm that he is able to get this working by opening a web server, before closing this issue.
suppressMessages(library('rCharts'))
dt1 <- dTable(corpUS, sPaginationType = "full_numbers", iDisplayLength = 10, sScrollX = "100%")
## http://bl.ocks.org/ramnathv/raw/8084330/
dt1$show('iframesrc', cdn = TRUE)
#'@ dt1$show('inline', include_assets = TRUE) #keep loading but unable display anything
#'@ dt1$show('inline', include_assets = TRUE, cdn = TRUE) #blank table frame shown
is works for me. http://bl.ocks.org/ramnathv/raw/8084330/
So is the plan to close this issue without fixing the inline option? save("abc.html",standalone=TRUE)
is working for me, but it's not a great workflow for jekyll.
I am using the command below to include an rChart is an rmarkdown standalone html document
This generates a pandoc error stating the included
js
files cannot be foundI think the fix here is to change
add_lib_assets
to prependhttp:
to the script paths and wrap them in single quotes. There also appears to be an additional double quote added to thehighcharts-more.js
path.The existing tags are
and after these changes they become
I've tested this change via a custom knitr hook, and the resulting doc is now standalone.