python - Display Bokeh generated file using Tornado -
I am trying to develop a web site where a file can upload, which then generate interactive data Has been analyzed back (a scatter plot and a histogram), which then returns to the browser to manipulate the user. (Imagine typing Excel online, upload a file, get a figure, and manipulate data.) I have considered many options and decided to go with Bokay for plotting. I wrote a python script and an html page to upload a file. Using Bokey, I was able to create an output file (like "plot.html"). it works well.
Separately, I have installed Torndada so that I can upload and dynamically read a simple file (like "test.txt"), and just return the contents of the file back to output. So it works well
However, when I modify the written script for use with Tornado, before that, the plot generated by Bokeh displays html, it does not work . Is there anything about Bokel Generated HTML (containing Plot Objects) that can not be rendered properly by Tornado? For example, I have read that an entry from Database Search may contain elements which can not be serialized, and it is necessary to remove non-serializable elements before the search results are displayed. I am thinking that something like this could happen.
Here are some relevant scripts:
display.py: This works to read and return the contents of the file using Tornado and It is expected, as the content of test.txt gives.
Import os.path Import Import Imported Ternado HitSparent Import Tornado.Oolope Import Tornado Options import from Tornado. Define options import, define options ("port", default = 80, help = "run on given port", type = int) category index handler (Tornado.web request handler): def mill (auto): self. Render ('index .html') class output handler (Tornado.web request handler): def post (self): fname = self.get_argument ('upfile') f = open (fname, 'r') line = f.readlines () Self.render ('Plot.html', content = lines) if __name__ == '__main__': tornado.options.parse_command_line () ap = ternado.web.app (handlers = [(r '/', indexhand R), (r '/ content', output handler)], template_path = os.path.join (os.path.dirname (__ file__), "templates"), static_path = os.path.join (os.path.dirname (__ Fail__), "stable"), debug = true) Http_server = torn AdokhttpserverkHTTpserver (AP) Http_serverklisten (Optionskport) Tornado. Loloop.IOLoop.instance (). Start ()
plot.py : To read and create a plot using Bokeh This works and makes plots generated in plot.html. Bokeh.plotting import * output_file ( "plot.html") from filename = 'test.dat' f = open (filename, 'r') deleted line #### to tampering ##### # data # scatter (ndarray [: 1000,0], ndarray [: 1000,1], color = 'red', alpha = 0.7) Tractors (up = hist, bottom = Anpikjoros (lane (hist)), left = edge [: - 1], right = edges [1:], fill_color = "# 036564", line_color = "# 033649")
display_plot.py : To display a Bokke-built plot HTML via Tokenado. It does not work.
Import imports. Imported imported imported toardado HitSparent Import Tornado Laodap Import Tornado Import option from Tornado. Define option import, define options ("port", default = 80, support = "run on the given port", type = int) class index handler (Tornado.web.resagehandler): df mill (auto): self. 'Plot.html') # The rest are in display.py for now
This is the last script that I was led to think that one with conspiracy objects Other HTML fonts that show Bokel Generated HTML Ailon can only be presented in text and figures can not be displayed, which correctly whether it is true and I plot.html to use the Tornado (or any Web service for that matter) What can I do to display?
Thank you for your help.
RequestHandler.render
is a file interpreted as Torndo template . This means that certain character sequences (especially double curly braces {{}}
) have special meaning. If you just want to serve the file, then render
instead of
:
open (with 'plot.html') )) As F: self.write (f.read ())
Comments
Post a Comment