mikedewar / d3py

a plottling library for python, based on D3
1.42k stars 201 forks source link

print html snippet from d3py #48

Closed alexdeng closed 12 years ago

alexdeng commented 12 years ago

scenario: In python web applications, one would want to insert d3 visualization with d3py by "printing" html snippet to an existing html. For example, googleVis package in R provides such functionality in its print function, which can be used with R markdown to produce html page easily.

mynameisfiber commented 12 years ago

You can access the string representations of all the code that has been created directly from the figure. For example, once you create a figure,

fig = Figure() + Line('x', 'y')

You can get the raw string code by looking at fig.html, fig.js, fig.css. All three objects can be safely casted to a string.

print "html: ", str(fig.html) print "js: ", str(fig.js) print "css: ", str(fig.css)

alexdeng commented 12 years ago

Thanks Micha! That is exactly what I was asking for. Do you think it worth providing a simple function to wrap the 3 parts(html, js. css) together?

--Alex

On Tue, Jun 26, 2012 at 9:08 PM, Micha Gorelick < reply@reply.github.com

wrote:

You can access the string representations of all the code that has been created directly from the figure. For example, once you create a figure,

fig = Figure() + Line('x', 'y')

You can get the raw string code by looking at fig.html, fig.js, fig.css. All three objects can be safely casted to a string.

print "html: ", str(fig.html) print "js: ", str(fig.js) print "css: ", str(fig.css)


Reply to this email directly or view it on GitHub: https://github.com/mikedewar/d3py/issues/48#issuecomment-6594286

mynameisfiber commented 12 years ago

@alexdeng I think adding such a specialty function would clutter the figure object! Also note that those properties (fig.(html|css|js)) are updated when you call fig.save().