Coder Social home page Coder Social logo

sxencon / datacamp-light Goto Github PK

View Code? Open in Web Editor NEW

This project forked from datacamp/datacamp-light

2.0 0.0 0.0 713 KB

Convert any blog or website to an interactive learning platform for data science

License: GNU General Public License v3.0

HTML 21.73% JavaScript 60.05% CSS 18.22%

datacamp-light's Introduction

DataCamp Light banner

DataCamp Light

  • Convert any website or blog to an interactive learning platform.
  • Works for both R and Python. Sessions are maintained on DataCamp's servers.
  • Convert existing markdown documents to an interactive course using the tutorial package.
  • Check out a demo R and Python example.
  • Leverage the same Submission Correctness Tests (SCT) DataCamp uses for all their courses. For R, there's the testwhat (GitHub wiki); for Python, there's pythonwhat (GitHub wiki).

Student flow

The user attempts to solve the exercise. DataCamp Light example 1

The user can play around in the interactive R or Python console on the right. DataCamp Light example 2

By giving automated feedback, the user is guided to the correct solution. DataCamp Light example 3

How to use?

Using the Wordpress plugin

Installation instructions can be found here.

Using the tutorial package

Convert existing .Rmd files to an interactive HTML by installing the tutorial R package.

Using the JavaScript library

You will first need to include the JavaScript library on your webpage. We recommend using the latest release on the DataCamp CDN (https://cdn.datacamp.com/datacamp-light-latest.min.js):

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

You can also use the JavaScript library in a stackoverflow.com answer by including the exercise and script tag as a snippet.

Writing the HTML block

After including the JavaScript library, you can start writing HTML blocks in the format below. These will be dynamically converted to exercises.

<div data-datacamp-exercise data-lang="r">
	<code data-type="pre-exercise-code">
		# This will get executed each time the exercise gets initialized
		b = 6
	</code>
	<code data-type="sample-code">
		# Create a variable a, equal to 5


		# Print out a


	</code>
	<code data-type="solution">
		# Create a variable a, equal to 5
		a <- 5

		# Print out a
		print(a)
	</code>
	<code data-type="sct">
		test_object("a")
		test_function("print")
		success_msg("Great job!")
	</code>
	<div data-type="hint">Use the assignment operator (<code><-</code>) to create the variable <code>a</code>.</div>
</div>

This code chunk will be transformed to the following exercise: DataCamp Light example 4

As we can see in the example, the whole exercise is contained in a single <div> element with two data attributes data-datacamp-exercise and data-lang. The first attribute data-datacamp-exercise indicates that the <div> should be treated as a DataCamp Light exercise, while the other attribute data-lang specifies which programming language should be used. The accepted values for data-lang are r and python. There is also an optional attribute data-height which can sets the height in px of the div (minimum height is 300px) or set the size according to the amount of sample code lines: data-height="auto".

Pre-Exercise Code

Pre-exercise code is executed when the R/Python session is initialized. You can use it to pre-load datasets, packages, etc. for students. The way to specify this is by defining a <code> tag containing your initialization code and set the data-type attribute to pre-exercise-code like this:

<code data-type="pre-exercise-code">
	# This will get executed each time the exercise gets initialized
	b = 6
</code>

In our example we initialize the (rather useless) variable b with value 6.

Sample Code

To set the sample code that will be present initially in the code editor, a <code> tag should be defined containing the sample code and the data-type attribute should be set to sample-code like this:

<code data-type="sample-code">
	# Create a variable a, equal to 5


	# Print out a


</code>

Our example simply shows a couple of comments together with some newlines. The JavaScript library also takes care of stripping leading indentation so no need to worry about that.

Solution

To set the solution code, a <code> tag should be defined containing the solution code and the data-type attribute should be set to solution-code like this:

<code data-type="solution">
	# Create a variable a, equal to 5
	a <- 5

	# Print out a
	print(a)
</code>

Submission Correctness Test (SCT)

A Submission Correctness Test is used to check whether the code submitted by the user properly solves the exercise. For detailed information on this you can look at the documentation for R and at the documentation for Python. The way to specify the SCT is by defining a <code> tag containing your SCT code and set the data-type attribute to sct like this:

<code data-type="sct">
	test_object("a")
	test_function("print")
	success_msg("Great job!")
</code>

In our example the first line checks whether the user declared the variable a and whether its value matches that of the solution code. The second line checks whether the print function is called and lastly a success message is specified that will be shown to the user when the exercise is successfully completed.

Hint

To specify a hint, a tag should be defined containing the hint and the data-type attribute should be set to hint like this:

<div data-type="hint">Use the assignment operator (<code><-</code>) to create the variable <code>a</code>.</div>

It is possible for the hint to contain for instance <code> tags as is the case in our example.

Load exercises added to DOM

To load datacamp-light exercises added to the DOM after the page loaded, call

window.initAddedDCLightExercises()

How does it work?

divs with the data-datacamp-exercise attribute are converted into a minimal version of DataCamp's learning interface (for the real deal, you can visit www.datacamp.com). It contains a session manager that connects to DataCamp's servers to provide an R or Python session as if you're working on your local system. The R and Python computing environments feature the most popular packages:

If you want to use a package that is not available, create an issue and we can install it (it's not possible to install packages at runtime).

Examples

You can find more examples in the example folder in the repository. You can also test out the demo R and Python example.

Building

After you downloaded this repository, run npm install and bower install for all the necessary dependencies. You will probably want to test your own build so change DCL_URL in src/datacamp-light.js to http://localhost:3003/. Afterwards you can run gulp to build DataCamp Light and node web.js to serve random examples with the local build.

datacamp-light's People

Contributors

ddmkr avatar filipsch avatar gl3nn avatar hannesbuseyne avatar iamarcel avatar ludov04 avatar rduque1 avatar rv2e avatar

Stargazers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.