I am trying this example and get an error. Is this the way to set up the
csv service
and call it? Do I need the .as_list() on the end of the select?
in default.py
def csvtab():
rows = db(db.ptoday.id>0).select( ).as_list()
for row in rows:
data = row.csvdata
ddata = ''.join(line.replace('\n', '\n') for line in data)
return data
@service.csv
def exposed():
mytable = csvtab()
If I want to serve csv tables as a web service, I call it from another
function which
has the @service.csv decorator. Is this right?
I put this path in the uri
http://127.0.0.1:8000/enp8/default/call/csv/exposed
I tried this and get an error:
<type 'exceptions.AttributeError'> 'dict' object has no attribute 'csvdata'
thanks for any help
On Monday, June 24, 2013 3:12:15 PM UTC-5, Anthony wrote:
>
> Do you want to embed the data in the page, or do you want to serve it as a
> CSV file? If you want to embed it in the page, you might need to embed it
> in some Javascript as a Javascript data structure rather than as pure HTML.
> To serve a CSV file, see http://web2py.com/books/default/chapter/29/10#CSV
> (you
> might be able to set the content type to 'text/csv' rather than what is
> shown in that example). You would then provide D3 with the URL that serves
> the CSV file (note, it doesn't actually generate a CSV file on the server
> -- it just uses a cStringIO object and sends its content as the HTTP
> response).
>
> Anthony
>
> On Monday, June 24, 2013 4:02:35 PM UTC-4, greaneym wrote:
>>
>> Relating to d3.js and csv files, I'm having two problems trying to get a
>> string object to load either
>>
>> 1. with d3.csv.parse or with
>>
>> 2. function() {return x; }
>>
>> right after the line,
>> g = new Dygraph( document.getElementById("div_pt"),
>>
>> that begins to generate a d3 graph.
>>
>>
>> The problem is similar to that on
>> http://stackoverflow.com/questions/14286461/django-and-d3-js-csv-data
>>
>> but I don't understand how to make the url "have a text content".
>>
>> Also, I am having a problem understanding what it means to use
>> the
>> function() return x
>>
>> as the method to return data to d3.js. I want to load a string value into
>> x
>> and have the graph display. When I use that and feed it {{=pt_data}} it
>> looks like the view source output at the bottom of this page.
>>
>> I am able to load a .csv file and produce a graph, but when I try to
>> create a string that can be loaded into function() {return x;} and it is
>> formatted as a csv
>> file, the graph doesn't load.
>> (disregard he timevalues).
>>
>>
>> The error console on the web inspector says,
>> syntax error, unexpected number, '00'
>> which means it is not parsing the date+time together.
>>
>> Does the string have to be formatted differently from the CSV file? They
>> look the same to me. How should the pt_data format in the browser's
>> 'view/source' look when it works?
>>
>> For reference, I read the docs files in dygraphs-master docs/data.html as
>> well as many other d3.js tutorials, but so far have not found an answer.
>> This project will also use json objects, but before that I want to get
>> the csv as string object working first.
>>
>>
>> <!DOCTYPE html>
>> <html>
>> <head>
>> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7;
>> IE=EmulateIE9">
>> <title>Summary</title>
>> <!--[if IE]>
>> <script type="text/javascript"
>> src="../../static/dygraphjs/excanvas.js"></script>
>> <![endif]-->
>>
>> <script src="/enp8/static/dygraphjs/dygraph-dev.js"
>> type="text/javascript"></script>
>> <script src="/enp8/static/dygraphjs/d3.v3.js"
>> type="text/javascript"></script>
>>
>> </head>
>> <body>
>> <h6>pt_data is 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 </h6>
>> <p>Power Today Data:</p>
>> <div id="div_pt" style="width:600px; height:300px;"></div>
>> <script type="text/javascript">
>> g = new Dygraph( document.getElementById("div_pt"),
>> d3.csv.parse(=URL('power_today', 'index')}} ; }
>> { }
>> );
>>
>>
>> </script>
>>
>> <!--<table width="100%">-->
>> <table width="75%">
>> <tr>
>> <h2>Summary 2011-09-10 </h2>
>> <td><h5><ul>Intervals:</h5></ul> 300</h5></td>
>> <td><h5><ul>Power (W):</h5></ul> [0, 0, 0, 0, 32, 246, 250, 424, 500,
>> 678, 898, 525, 400, 379, 184, 41, 0, 0, 0, 0]</h5></td>
>> </tr>
>> <br>
>> <br>
>>
>> </table>
>>
>> <h5> JSON data formatted via python</h5>
>> {u'first_interval_end_date':
>> u'2011-09-10T00:05-7:00', u'production': [0, 0, 0, 0,
>> 32, 246, 250, 424, 500, 678, 898, 525, 400, 379, 184, 41, 0, 0, 0, 0],
>> u'interval_length': 300}
>>
>>
>>
>> </body>
>> </html>
>>
>>
>>
>> Thanks a lot for any help or suggestions.
>>
>> Margaret
>>
>>
--
---
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.