Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Reddit Widget for Dashing



Took a little inspiration from the News widget to construct this Reddit widget. Simply add the subreddit .json feed URLs that you want to the top of the reddit.rb job script, and the widget will cycle through each one, showing top posts, their score, and comment count. You can also set the maxcount higher or lower, the default is 5 posts.


To use this widget, copy reddit.html,, and reddit.scss into the /widgets/reddit directory. Put the reddit.rb file in your /jobs folder.

To include the widget in a dashboard, add the following snippet to the dashboard layout file:

<li data-row="1" data-col="1" data-sizex="4" data-sizey="1">
  <div data-id="reddit" data-view="Reddit"></div>
class Dashing.Reddit extends Dashing.Widget
ready: ->
@currentIndex = 0
@titleElem = $(@node).find('.subreddit-title')
@dataElem = $(@node).find('.subreddit-data')
@top_posts = @get('posts')
onData: (data) ->
@currentIndex = 0
startCarousel: ->
setInterval(@nextSubreddit, 8000)
nextSubreddit: =>
if @top_posts
@dataElem.fadeOut =>
@set 'posts', @top_posts[@currentIndex]
@currentIndex = (@currentIndex + 1) % @top_posts.length
<table class="reddit-posts">
<th class="subreddit-title" data-bind="posts.label" colspan="3">Loading...</th>
<th class="post-title">Title</th>
<th class="post-upvotes">Upvotes</th>
<th class="post-comments">Comments</th>
<tbody class="subreddit-data">
<tr data-foreach-item="posts.items">
<td class="post-title" data-bind="item.title"></td>
<td class="post-score" data-bind="item.score"></td>
<td class="post-comments" data-bind="item.comments"></td>
require 'net/http'
require 'json'
class Reddit
def initialize()
# add your desired subreddits here
@subreddits = {
'/r/programming' => '',
'/r/webdev' => '',
'/r/drupal' => '',
'/r/ruby' => '',
# the limit per subreddit to grab
@maxcount = 5
def getTopPostsPerSubreddit()
posts = [];
@subreddits.each do |subreddit, url|
response = JSON.parse(Net::HTTP.get(URI(url)))
if !response
puts "reddit communication error for #{@subreddit} (shrug)"
items = []
for i in 0..@maxcount
title = response['data']['children'][i]['data']['title']
trimmed_title = title[0..85].gsub(/\s\w+$/, '...')
title: trimmed_title,
score: response['data']['children'][i]['data']['score'],
comments: response['data']['children'][i]['data']['num_comments']
posts.push({ label: 'Current top posts in "' + subreddit + '"', items: items })
@Reddit =;
SCHEDULER.every '2m', :first_in => 0 do |job|
posts = @Reddit.getTopPostsPerSubreddit
send_event('reddit', { :posts => posts })
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #12b0c5;
$title-color: rgba(255, 255, 255, 0.7);
$moreinfo-color: rgba(255, 255, 255, 0.7);
// ----------------------------------------------------------------------------
// Widget-list styles
// ----------------------------------------------------------------------------
.widget-reddit {
background-color: $background-color;
vertical-align: top !important;
.title {
color: $title-color;
th, td {
text-align: left;
} {
max-width: 350px;
.updated-at {
color: rgba(0, 0, 0, 0.3);
.more-info {
color: $moreinfo-color;
Copy link

geebru commented Dec 31, 2013

@MaxCount doesn't seem to work properly. If set to 1, I still get 2 posts.

In addition, when the scheduler runs the "getTopPostsPerSubreddit" my entire widget goes blank (no data) until it refreshes. Any ideas?

Copy link

HLFH commented Mar 31, 2014

In addition, when the scheduler runs the "getTopPostsPerSubreddit" my entire widget goes blank (no data) until it refreshes.

Reddit.rb does not work.

Copy link

magicguitarist commented Apr 8, 2014

My dashboard's reddit widget hasn't updated since I installed it. Refreshes, restarting the service. Do dice.

Copy link

nic-lan commented Jul 24, 2015

line 5 in reddit.rb.
You should remove the ',' if you want to be able to use the widget since it's the last element of the hash.

Copy link

nic-lan commented Jul 24, 2015

sorry i meant line 11

Copy link

minisaurus commented Jan 14, 2016

I changed the reddits to display in the .rb file, restarted, and the default reddits are still showing. I'm out of ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment