[web2py] Re: D3.js calling Json in View

2014-05-26 Thread thehuman trashcan
Ah right - that makes sense.

Thanks again ;-)

On Saturday, 24 May 2014 03:55:39 UTC+1, Andrew W wrote:
>
> good work.  data just refers to the dictionary.  When you open up your 
> json file you just see a dictionary with one key that points to an array.
> By saying data.dashboard_data you are then directly referencing the value 
> of the key, ie. the array in the dictionary.  
>
> There are several ways to do this which I must post to web2pyslices soon, 
> but yours is one of them, and it works !
>
> web2py with d3 is a good combo.   I plan to do a lot more with the two 
> combined.
>
>
>
> On Friday, May 23, 2014 10:04:17 PM UTC+10, thehuman trashcan wrote:
>>
>> In my impatience I just quickly edited the file.  data.dashboard_data is 
>> all that was needed.
>>
>> I have managed to leave Scheme=true.
>>
>> I don't fully understand how data.dashboard_data converts my dictionary 
>> to an array, but I will be looking into this to understand.
>>
>> In any case, thank you ever so much!
>>
>>
>> On Friday, 23 May 2014 05:41:16 UTC+1, Andrew W wrote:
>>>
>>> Also, try scheme='https' in your case. See Core chapter of book.
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: D3.js calling Json in View

2014-05-23 Thread Andrew W
good work.  data just refers to the dictionary.  When you open up your json 
file you just see a dictionary with one key that points to an array.
By saying data.dashboard_data you are then directly referencing the value 
of the key, ie. the array in the dictionary.  

There are several ways to do this which I must post to web2pyslices soon, 
but yours is one of them, and it works !

web2py with d3 is a good combo.   I plan to do a lot more with the two 
combined.



On Friday, May 23, 2014 10:04:17 PM UTC+10, thehuman trashcan wrote:
>
> In my impatience I just quickly edited the file.  data.dashboard_data is 
> all that was needed.
>
> I have managed to leave Scheme=true.
>
> I don't fully understand how data.dashboard_data converts my dictionary to 
> an array, but I will be looking into this to understand.
>
> In any case, thank you ever so much!
>
>
> On Friday, 23 May 2014 05:41:16 UTC+1, Andrew W wrote:
>>
>> Also, try scheme='https' in your case. See Core chapter of book.
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: D3.js calling Json in View

2014-05-23 Thread thehuman trashcan
In my impatience I just quickly edited the file.  data.dashboard_data is 
all that was needed.

I have managed to leave Scheme=true.

I don't fully understand how data.dashboard_data converts my dictionary to 
an array, but I will be looking into this to understand.

In any case, thank you ever so much!


On Friday, 23 May 2014 05:41:16 UTC+1, Andrew W wrote:
>
> Also, try scheme='https' in your case. See Core chapter of book.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: D3.js calling Json in View

2014-05-23 Thread thehuman trashcan
Thank you so much Andrew - you have given me plenty to work on...

When I'm back I'll give these a go and let you know how I get on.

Many thanks again

On Friday, 23 May 2014 05:41:16 UTC+1, Andrew W wrote:
>
> Also, try scheme='https' in your case. See Core chapter of book.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: D3.js calling Json in View

2014-05-22 Thread Andrew W
Also, try scheme='https' in your case. See Core chapter of book.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: D3.js calling Json in View

2014-05-22 Thread Andrew W
I'm not at a desktop machine so I'll be brief.
D3 expects an array, you have provided a dict.
When you reference "data" such as in the foreach, try data.dashboard_data which 
will reference the array.  Syntax is probably not quite correct.

Also, if you're not sure add console.log stmts to show the data.  I used this a 
lot to better understand what's happening and to debug.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: D3.js calling Json in View

2014-05-22 Thread thehuman trashcan
Hi Andrew,

The URL line now says:

d3.json("{{=URL('default', 'dashboard_data.json', scheme=True, host=True)}}"
, function (data) {

This doesn't make the information come back though.  Does it matter that I 
am using pythonanywhere - it looks like they have https:// in place?

Thanks!!



On Wednesday, 21 May 2014 11:08:42 UTC+1, Andrew W wrote:
>
> In the URL() call, add scheme=True, host=True.   

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: D3.js calling Json in View

2014-05-21 Thread thehuman trashcan
Hi Andrew,

The JSON output is attached (I just grabbed the first 250 lines of some 
public data).

My controller code:

def dashboard_data():
dashboard_data = db().select(db.com_house_stock.CompanyNumber, 
db.com_house_stock.IncorporationDate, db.com_house_stock.CompanyCategory, 
orderby=db.com_house_stock.CompanyNumber)
return dict(dashboard_data=dashboard_data)


def visualisation():
return dict(message=T('Test dashboard'))

And just in case, the visualisation.html code (at the moment I am just 
trying to make the code show a table, with just one column of data, get 
this to work before I move onto anything more complicated!):

{{
  response.files.append(URL('static','js/d3.js'))
  response.files.append(URL('static','js/crossfilter.js'))
  response.files.append(URL('static','js/dc.js'))
}}
{{extend 'layout.html'}}

Open source data dashboard
Pie chart displaying percentages of each category in the database


  

  

  
IncDate
  

  

  



{{# create dc.js chart object & link to DIV}}
var dataTable = dc.dataTable("#dc-table-graph");

{{# load data}}
d3.json("{{=URL('default', 'dashboard_data.json')}}", function (data) {

{{# format data}}
  var dtgFormat = d3.time.format("%d/%m/%Y");

  data.forEach(function (d) {
  d.incdate = dtgFormat.parse(d.IncorporationDate);
  });

{{# run data through crossfilter}}
  var facts = crossfilter(data);
  
  {{# Create dataTable dimension}}
  var timeDimension = facts.dimension(function (d) {
return d.incdate;
  });

 dataTable.width(960).height(800)
.dimension(timeDimension)
.group(function(d) { return "Table"
 })
.size(10)
.columns([
  function(d) { return d.incdate; }
])
.sortBy(function(d){ return d.incdate; })
.order(d3.ascending);

dc.renderAll ();
   });





Thanks for any pointers you can give!!!




On Tuesday, 20 May 2014 17:36:04 UTC+1, Andrew W wrote:
>
> I use this technique regularly.  Show the controller code and/or json 
> output and I'll have a look.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


dashboard_data.json
Description: Binary data


[web2py] Re: D3.js calling Json in View

2014-05-21 Thread Andrew W
In the URL() call, add scheme=True, host=True.   

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: D3.js calling Json in View

2014-05-20 Thread thehuman trashcan
Thanks Anthony,

When I manually load the JSON file I do see the correct data.  The Network 
activity (I am using Chrome) seems to show that it pulled the JSON file 
back ok.  

But I cannot see an Ajax request?? I do see that the D3.JS returns with a 
304 status, NOT MODIFIED.  Thanks for your suggestion I guess maybe there 
is something wrong with the D3 code...



On Tuesday, 20 May 2014 14:44:25 UTC+1, Anthony wrote:
>
> When you manually go to /yourapp/default/dashboard_data.json, do you get 
> the JSON you expect? If so, when you load the page in question, if you 
> watch the network activity in the browser developer tools, do you see an 
> Ajax request successfully pulling in that JSON? If all that works, then the 
> problem must be either with the format of the JSON or with your D3 code.
>
> Anthony
>
> On Tuesday, May 20, 2014 9:08:34 AM UTC-4, thehuman trashcan wrote:
>>
>> Hi,
>>
>> I am following the instructions at: 
>> https://leanpub.com/D3-Tips-and-Tricks/read#leanpub-auto-crossfilter-dcjs-and-d3js-for-data-discoveryand
>>  trying to put this into web2py.
>>
>> I created the database in the db.py, populated it with some data.
>> I have created a controller which queries the database, and created a 
>> JSON view (default/dashboard_data.json) pulling this data back.
>>
>> I have a view (visualisation.html) with the following code:
>>
>> {{
>>   response.files.append(URL('static','js/d3.js'))
>>   response.files.append(URL('static','js/crossfilter.js'))
>>   response.files.append(URL('static','js/dc.js'))
>> }}
>> {{extend 'layout.html'}}
>>
>> Open source data dashboard
>> Pie chart displaying percentages of each category in the database
>>
>> 
>>   
>> 
>>   
>> 
>>   
>> IncDate
>>   
>> 
>>   
>> 
>>   
>> 
>>
>> 
>> {{# create dc.js chart object & link to DIV}}
>> var dataTable = dc.dataTable("#dc-table-graph");
>>
>> {{# load data}}
>> d3.json("{{=URL('default', 'dashboard_data.json')}}", function (data) {
>> 
>> {{# format data}}
>>   var dtgFormat = d3.time.format("%d/%m/%Y");
>> 
>>   data.forEach(function (d) {
>>   d.incdate = dtgFormat.parse(d.IncorporationDate);
>>   });
>>
>> {{# run data through crossfilter}}
>>   var facts = crossfilter(data);
>>   
>>   {{# Create dataTable dimension}}
>>   var timeDimension = facts.dimension(function (d) {
>> return d.incdate;
>>   });
>>
>>  dataTable.width(960).height(800)
>> .dimension(timeDimension)
>> .group(function(d) { return "Table"
>>  })
>> .size(10)
>> .columns([
>>   function(d) { return d.incdate; }
>> ])
>> .sortBy(function(d){ return d.incdate; })
>> .order(d3.ascending);
>>
>> dc.renderAll ();
>>});
>> 
>> 
>>
>>
>>
>> I think the problem is with referencing the JSON file in the URL, but I 
>> don't seem to be able to find the correct method of doing this in the book. 
>>  If that's not the problem, then I really have no idea where to begin!
>>
>> If anyone could help at all, I would really appreciate it.
>>
>> Many thanks
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: D3.js calling Json in View

2014-05-20 Thread Andrew W
I use this technique regularly.  Show the controller code and/or json output 
and I'll have a look.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: D3.js calling Json in View

2014-05-20 Thread Anthony
When you manually go to /yourapp/default/dashboard_data.json, do you get 
the JSON you expect? If so, when you load the page in question, if you 
watch the network activity in the browser developer tools, do you see an 
Ajax request successfully pulling in that JSON? If all that works, then the 
problem must be either with the format of the JSON or with your D3 code.

Anthony

On Tuesday, May 20, 2014 9:08:34 AM UTC-4, thehuman trashcan wrote:
>
> Hi,
>
> I am following the instructions at: 
> https://leanpub.com/D3-Tips-and-Tricks/read#leanpub-auto-crossfilter-dcjs-and-d3js-for-data-discoveryand
>  trying to put this into web2py.
>
> I created the database in the db.py, populated it with some data.
> I have created a controller which queries the database, and created a JSON 
> view (default/dashboard_data.json) pulling this data back.
>
> I have a view (visualisation.html) with the following code:
>
> {{
>   response.files.append(URL('static','js/d3.js'))
>   response.files.append(URL('static','js/crossfilter.js'))
>   response.files.append(URL('static','js/dc.js'))
> }}
> {{extend 'layout.html'}}
>
> Open source data dashboard
> Pie chart displaying percentages of each category in the database
>
> 
>   
> 
>   
> 
>   
> IncDate
>   
> 
>   
> 
>   
> 
>
> 
> {{# create dc.js chart object & link to DIV}}
> var dataTable = dc.dataTable("#dc-table-graph");
>
> {{# load data}}
> d3.json("{{=URL('default', 'dashboard_data.json')}}", function (data) {
> 
> {{# format data}}
>   var dtgFormat = d3.time.format("%d/%m/%Y");
> 
>   data.forEach(function (d) {
>   d.incdate = dtgFormat.parse(d.IncorporationDate);
>   });
>
> {{# run data through crossfilter}}
>   var facts = crossfilter(data);
>   
>   {{# Create dataTable dimension}}
>   var timeDimension = facts.dimension(function (d) {
> return d.incdate;
>   });
>
>  dataTable.width(960).height(800)
> .dimension(timeDimension)
> .group(function(d) { return "Table"
>  })
> .size(10)
> .columns([
>   function(d) { return d.incdate; }
> ])
> .sortBy(function(d){ return d.incdate; })
> .order(d3.ascending);
>
> dc.renderAll ();
>});
> 
> 
>
>
>
> I think the problem is with referencing the JSON file in the URL, but I 
> don't seem to be able to find the correct method of doing this in the book. 
>  If that's not the problem, then I really have no idea where to begin!
>
> If anyone could help at all, I would really appreciate it.
>
> Many thanks
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.