datacamp / tutorial

R Package to convert R Markdown files to DataCamp Light HTML files
Other
86 stars 31 forks source link

Adding DataCamp Light to bookdown #22

Closed ismayc closed 7 years ago

ismayc commented 7 years ago

I'm hoping to add some exercises to a bookdown book, but am not getting the R Markdown chunks to render in the HTML file. All that I get is something like this in the HTML file

By default, `tutorial` will convert all R chunks.

eyJsYW5ndWFnZSI6InIiLCJzYW1wbGUiOiJhIDwtIDJcbmIgPC0gM1xuXG5hICsgYiJ9

The Rmd I am using is at https://gist.github.com/ismayc/5e8c046a7e7bdaafbaba2db2be8eae94 .

It appears that adding in the chapter headers via # is what causes the chunk to just produce the text instead of the DataCamp window.

Here is my session info:

> devtools::session_info()
Session info -----------------------------------------------------------
 setting  value                       
 version  R version 3.3.2 (2016-10-31)
 system   x86_64, darwin13.4.0        
 ui       RStudio (1.1.39)            
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/Los_Angeles         
 date     2017-02-18                  

Packages ---------------------------------------------------------------
 package   * version date       source        
 backports   1.0.5   2017-01-18 CRAN (R 3.3.2)
 bookdown    0.3     2016-11-28 CRAN (R 3.3.2)
 devtools    1.12.0  2016-06-24 CRAN (R 3.3.0)
 digest      0.6.12  2017-01-27 CRAN (R 3.3.2)
 evaluate    0.10    2016-10-11 CRAN (R 3.3.0)
 htmltools   0.3.5   2016-03-21 CRAN (R 3.3.0)
 knitr       1.15.1  2016-11-22 CRAN (R 3.3.2)
 magrittr    1.5     2014-11-22 CRAN (R 3.3.0)
 memoise     1.0.0   2016-01-29 CRAN (R 3.3.0)
 Rcpp        0.12.9  2017-01-14 CRAN (R 3.3.2)
 rmarkdown   1.3     2016-12-21 CRAN (R 3.3.2)
 rprojroot   1.2     2017-01-16 CRAN (R 3.3.2)
 stringi     1.1.2   2016-10-01 CRAN (R 3.3.0)
 stringr     1.1.0   2016-08-19 CRAN (R 3.3.0)
 withr       1.0.2   2016-06-20 CRAN (R 3.3.0)
 yaml        2.1.14  2016-11-12 CRAN (R 3.3.2)
filipsch commented 7 years ago

Hey @ismayc, basically, the tutorial package converts your R Markdown chunks into html that DataCamp Light understands, and then includes a <script> tag to the top of the document to import the datacamp light javascript library:

<script src=https://cdn.datacamp.com/datacamp-light-latest.min.js></script>

It appears that bookdown does some magic with the HTML content and the scripts to split up the content into different pages for each chatper. The script tag that refers to datacamp light is lost in translation. If you just update your example as follows:

---
title: "Example Document"
author: "Your name here"
output:
  bookdown::gitbook
---

# Chap 1

<script src=https://cdn.datacamp.com/datacamp-light-latest.min.js></script>

## Sec 1

```{r, include=FALSE}
tutorial::go_interactive(greedy=FALSE)
```

By default, `tutorial` will convert all R chunks.

```{r tut=TRUE}
a <- 2
b <- 3

a + b
```

(so basically hardcoding the script tag in each chapter), the blocks should render fine. It's possible that you might have to do some CSS tweaking to not have the themes interfere with the datacamp light css to render the chunks; that's an open issue on the datacamp-light project.

I could also solve this in tutorial itself, by automatically including the <script> tag before every datacamp light chunk I include, but that would mean including the script potentially dozens of times, which is not good practice.

I hope this answers your question!

filipsch commented 7 years ago

@ismayc did it work?

ismayc commented 7 years ago

It is working! Thanks, @filipsch. I'm not quite sure that I want to go through copying all of the questions from my DataCamp course into the book though on second thought, especially with the chunk syntax being a little different.

{r ex="joining-data-frames", type="pre-exercise-code", tut=TRUE}

versus

--- type:NormalExercise lang:r xp:100 skills:1 *** =pre_exercise_code

Does the DataCamp syntax work on DataCamp Light or vice versa? Or is there a way to reference problems on DataCamp already for use in DataCamp Light?

Also, it appears the links at the bottom of https://cran.r-project.org/web/packages/tutorial/vignettes/tutorial-basics.html are no longer active as they just route to the DataCamp course.

filipsch commented 7 years ago

@ismayc Unfortunately, it's not yet possible to 'port' DataCamp Light-formatted exercises to regular DataCamp exercises or vice versa. The big difference is that the DataCamp exercises live in DataCamp's database, while for DCL, they just exist in the web page.

I think it should be possible, though, to be able to reference an exercise, so it can be fetched from the database, and then have a tutorial helper function generate a DataCamp light version of it; that shouldn't be too hard. I'll open up a new issue for that.

About the links: thanks, good find, i'll update that in the next version of tutorial.

aaramirez commented 6 years ago

When you have split-by: section does not work adding the Githubissues.

  • Githubissues is a development platform for aggregating issues.