gottfrois / dashing-rails

The exceptionally handsome dashboard framework for Rails.
MIT License
1.45k stars 149 forks source link

How to push data into widget using dashing dashboard #101

Closed abhin123 closed 7 years ago

abhin123 commented 7 years ago

I want to push numeric data from a file to my dashboard.

I am using the following .rb file as job for pushing the data

SCHEDULER.every '30s' do var = File.open("/dashing/abhi/sample.txt", "r") var.each_line do |line| puts line send_event('polarion', { value: var }) end end

But the data is not being displayed in dashboard.

gottfrois commented 7 years ago

make sure the widget id is the same as the one you send on send_event

abhin123 commented 7 years ago

Thanks for responding. Yes, its the same. While replacing the send_event line in .rb file with the folowing send_event('polarion', { value: rand(100) }) its getting dispalyed correctly but i want the content in /dashing/abhi/sample.txt which is a number to be displayed in the dashboard.

gottfrois commented 7 years ago

var.to_i maybe? it expects a number

abhin123 commented 7 years ago

Thanks for the suggestion. Even after the changes, the value is not been displayed on the dashboard. I have modifed the .rb file to

SCHEDULER.every '30s' do var = File.open("/dashing/abhi/sample.txt", "r") var.each_line do |line| puts line send_event('polarion', { value: var.to_i }) end end

But still no luck. Any help in this is highly appreciated. I am a beginner, setting the dashboard for the first time.

gottfrois commented 7 years ago

send_event('polarion', { value: line.to_i })

abhin123 commented 7 years ago

Applied the changes, still the result is the same. The ouput of the file /dashing/abhi/sample.txt is a number just one line.

abhin123 commented 7 years ago

I am getting the value with this.

var = File.open("/dashing/abhi/sample.txt", "r") SCHEDULER.every '30s' do send_event('polarion', { current: var.gets.to_i }) end

But the value goes after refreshing looks like the value is not appearing once the scheduler runs. It takes the value for the first time and when the scheduler runs value turns to zero.

gottfrois commented 7 years ago

because the first time you read the value, the file cursor stays a the end of the file and there is nothing more to read. You need to open/read the file every time or put the cursor back at the beginning of the file every time.

abhin123 commented 7 years ago

Hi, Can you please suggest a method so that the value in the file gets displayed?

abhin123 commented 7 years ago

Finnaly got it working. Thanks a lot for your help

gottfrois commented 7 years ago

np, glad you figured this out :)