Important Note:We need to update the configuration in development to handle multiple requests at the same time. One request for the page we’re working on, and another request for the Server Sent Event controller.

Every new Dashing project comes with sample widgets & sample dashboards for you to explore. The directory is setup as follows:

app/views/dashing/dashboards — One .erb file for each dashboard that contains the layout for the widgets.

app/jobs — Your ruby jobs for fetching data (e.g for calling third party APIs like twitter).

app/views/layouts/dashing/ — All your custom layouts where your dashboards and widgets will be included.

Getting Data Into Your Widgets

Providing data to widgets is easy. You specify which widget you want using a widget id, and then pass in the JSON data. There are two ways to do this:

Jobs

Dashing uses rufus-scheduler to schedule jobs. You can make a new job with rails g dashing:job sample_job, which will create a file in the jobs directory called sample_job.rb.

Example:

# :first_in sets how long it takes before the job is first run. In this case, it is run immediately
Dashing.scheduler.every'1m',first_in:1.second.sincedo|job|Dashing.send_event('karma',{current:rand(1000)})end

This job will run every minute, and will send a random number to ALL widgets that have data-id set to "karma".

Jobs are where you put stuff such as fetching metrics from a database, or calling a third party API like Twitter. Since the data fetch is happening in only one place, it means that all instances of widgets are in sync.

where * can be anything. This give you all the flexibility you need to push to redis. For example the send_event method provided by Dashing uses the following namespace:

redis.publish("dashing_events.create",{})

You can configure the redis namespace in config/initializers/dashing.rb:

config.redis_namespace='your_redis_namespace'

API

Widgets

Your widgets can be updated directly over HTTP. Post the data you want in json to /dashing/widgets/widget_id. For security, you will also have to include your auth_token (which you can generate in config/initializers/dashing.rb).