datacamp-light
datacamp-light copied to clipboard
Including datacamp light in a Shiny app
Based on this question I see that it is possible to include datacamp widgets into shiny. At least the widgets show up, but there seems to be an issue with the session or the connection between shiny and datacamp as the Run/Submit buttons wont activate. I tried to include those versions without success:
- https://cdn.datacamp.com/dcl-react.js.gz
- https://cdn.datacamp.com/datacamp-light-latest.min.js
- https://cdn.datacamp.com/dcl-react-dev.js.gz
Am I missing something or is it not that easy to include a widget to shiny?
Thats the R/shiny code:
library(shiny)
library(shinydashboard)
ui <- shinyUI(
dashboardPage(
header = dashboardHeader(title = 'R Code'),
sidebar = dashboardSidebar(menu),
body = dashboardBody(
tags$head(tags$script(src = 'https://cdn.datacamp.com/dcl-react.js.gz')),
# tags$head(tags$script(src = 'https://cdn.datacamp.com/datacamp-light-latest.min.js')),
# tags$head(HTML('<script async src="https://cdn.datacamp.com/dcl-react-dev.js.gz"></script>')),
tags$head(tags$script('$( document ).ready(function() {
initAddedDCLightExercises();
});')),
HTML('
<div class="exercise">
<div class="title">
<h2>How it works</h2>
</div>
<div data-datacamp-exercise data-lang="r" data-height="500">
<code data-type="pre-exercise-code"># no pec</code>
<code data-type="sample-code">
# Calculate 3 + 4
3 + 4
# Calculate 6 + 12
</code>
<code data-type="solution">
# Calculate 3 + 4
3 + 4
# Calculate 6 + 12
6 + 12</code>
<code data-type="sct">
test_output_contains("18", incorrect_msg = "Make sure to add `6 + 12`
on
a new line. Do not start the line with a `#`, otherwise your R code is not executed!")
success_msg("Awesome! See how the console shows the result of the R code you
submitted? Now that you're familiar with the interface, let's get down to R
business!")
</code>
<div data-type="hint">
<p>Just add a line of R code that calculates the sum of 6 and 12, just like the
example
in the sample code!</p>
</div>
</div>
</div>'
)
)
)
)
server <- function(input, output) {}
shinyApp(ui, server)