Anthony, I look forward to your incorporation of d3 into web2py! Maybe you have enough d3 knowledge to help me make this work.
in my controller, powertoday.py there is a function, def csvtab(): #return dict(rows = db(db.ptoday.id>0).select( )) rows = db(db.ptoday.id>0).select( ) for row in rows: data = row.csvdata # d3data = data="".join(line.rstrip() for line in data) # all in one line ddata = ''.join(line.replace('\n', '\n') for line in data) return ddata ddata is a typed as a string, according to the output of type(ddata) then I have a view file csvtab.html {{ =ddata }} when viewed, ddata looks like this, Date,ENWH 2011/09/10 00:05,0 2011/09/10 00:05,0 2011/09/10 00:05,0 2011/09/10 00:05,0 2011/09/10 00:05,32 2011/09/10 00:05,246 2011/09/10 00:05,250 2011/09/10 00:05,424 2011/09/10 00:05,500 2011/09/10 00:05,678 2011/09/10 00:05,898 2011/09/10 00:05,525 2011/09/10 00:05,400 2011/09/10 00:05,379 2011/09/10 00:05,184 2011/09/10 00:05,41 2011/09/10 00:05,0 2011/09/10 00:05,0 2011/09/10 00:05,0 2011/09/10 00:05,0 third, I have a .csv file for this view, csvtab.csv containing {{ import cStringIO stream=cStringIO.StringIO() ddata.export_to_csv_file(stream) response.headers['Content-Type']='text' response.write(stream.getvalue(),escape=False) }} and when I view this file it looks like this: Date,ENWH 2011/09/10 00:05,0 2011/09/10 00:05,0 2011/09/10 00:05,0 2011/09/10 00:05,0 2011/09/10 00:05,32 2011/09/10 00:05,246 2011/09/10 00:05,250 2011/09/10 00:05,424 2011/09/10 00:05,500 2011/09/10 00:05,678 2011/09/10 00:05,898 2011/09/10 00:05,525 2011/09/10 00:05,400 2011/09/10 00:05,379 2011/09/10 00:05,184 2011/09/10 00:05,41 2011/09/10 00:05,0 2011/09/10 00:05,0 2011/09/10 00:05,0 2011/09/10 00:05,0 Do you have any suggestions for how to get d3 to look at the csvtab.csv file? I've tried many, many things (I want to get the csv as python solution working), including this, g = new Dygraph( document.getElementById("div_pt"), d3.csv({{=URL('powertoday','cvstab.csv')}}), {} ); but that errors on the d3.csv line with "invalid flags supplied to reg exp constructor". The URL points to a valid csv file. I want to get a solution where a python obj is providing the csv content. I don't want to embed in the html dom. Have you tried this .csv method from the book? Any help very welcome. margaret On Tuesday, June 25, 2013 3:05:23 PM UTC-5, Anthony wrote: > > I would guess D3 would be faster if fed JSON (which is already Javascript) > rather than having to first parse CSV. > > Anthony > > On Tuesday, June 25, 2013 3:59:48 PM UTC-4, Andrew W wrote: >> >> Suggest you look at the book section "rendering a dictionary", I use the >> json approach with d3, and then reference the URL in the js script. Works >> great and should work for csv too. This approach allows you to get the >> file formatted in the way d3 expects it, without trying to do it in js code. >> >> I'm still working out the best approach of embedding the d3 js code in an >> app, controller (perhaps a hybrid of https://github.com/mikedewar/d3py), >> in the view or a separate js file. ? >> >> -- --- 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/groups/opt_out.