I recently started working on my very first dashboard application using dash.
The tutorials are comprehensible, however, I have a hard time handling the front end details because I cannot find an API reference. Specifically, each element accepts a style argument that let's us modify some CSS details, like text alignment, fonts etc. I have seen some examples in the tutorials but I would love to have an exhaustive list of everything I can pass there.
As an example, I want to create a table but the columns are too close together. I need to control the spacing between them and I imagine there should be an argument like padding, spacing, borderSize... you get the point. Where can I find these details?
It could be possible to edit some styling by passing some keywords to the Dash component. It depends on the component itself.
For example, if you are using DataTable from dash-table-experiment:
import dash_table_experiments as dt
help(dt.DataTable)
you can see that the API of this component allows you to set things like column_widths (list; optional) and min_width (number; optional).
If you need some more complex styling (e.g. a yellow background with linear gradient for all even table cells) I'm afraid you'll have to know some CSS.
A few additional resources:
Currently the Dash styleguide is based on the Skeleton CSS framework
Each dcc.Graph is composed by a figure and a layout. Here is the plotly.js figure reference
For things like showing/hiding legends, traces, etc, have a look at the plotly.js configuration options
For HTML: https://github.com/plotly/dash-html-components
For component: https://github.com/plotly/dash-core-components
Seems the dash project didn't create the user-friendly API document (I guess it was related to their business strategy).
The only way to get the help is the dash community and git-code project.
if you want help with python objects in dash then just use:
help(html.Div)
to get a list of argument parameters.
If you want to know what can be placed in the style parameter the answer is any and all css can be generated. You can customize the look anyway you want here is the syntax...
style={
'border':'1px solid #333',
'margin':'10px',
'padding':'10px',
'background-color':'#888',
'position':'absolute',
},
The style parameter excepts a dictionary object. In order for your CSS to be rendered it needs to be in the syntax above, which will create a python dictionary object.
Related
I have an interactive graph generated by Plotly in Python that I saved to an html file using plotly.offline.plot(fig, filename='/tmp/interactiveGraph.html')
I am now trying to embed this interactive graph into some kind of webpage, using either Dash or Django. I'm leaning toward Django at the moment, given that I have an html version of the graph. Which would be better?
My code for the webpage is in a separate file from the code where I am creating the graph.
A lot of the tutorials I've found online just say to add a few lines to the template, but I don't know how to get those lines that they've described.
tl;dr: I'm looking for guidance as how to integrate an html file-for a Plotly interactive graph-with a web python script using Django or Dash
Side Question:
what is the difference between
plotly.offline.plot(fig, include_plotlyjs=False, output_type='div')
and what I have above?
Reference:
https://github.com/ricleal/DjangoPlotLy
https://www.pythonsetup.com/how-implement-data-visualization-django-and-plotly/
I would highly reccomend Django, its a great framework. As for this, the best option is to generate the data via JavaScript and Plotly has a great library for this. If you must use python, then Django can be used. Assuming you are familiar with Django, inside of your view you can collect your data and build your graph ( I would reccomend a celery task for something long running like this unless they are small graphs), and you can then collect the return from creating the graph in div format. This will return a string that holds all the needed html and css for the graphs. Put this inside of you get_context_data() method in your view and place it into the dictionary. You can the use that object inside of a template. I have done this before, if you are having a hard time feel free to DM me. Hope this helps some!
In regards to your side question, I believe having False for including JS will make the graph a bit smaller assuming you have an include for the plotly JS library. They might have done this in a newer release to make the graphs faster as they were significantly slower in the browser from python that the JS rendered one.
I've been using Bokeh's datatable, but there are a few things I'd like to do that I don't know how to accomplish using the DataTable class. For example, I don't think it's possible add icons (or any images) to different rows, or setting the table to single selection only. So, I've been thinking about implementing just a HTML table, and writing it with the DIV widget.
However, I'd still like to add interactive features to the table, like buttons, or the icons mentioned above. Then, when an event is generated (e.g. onClick), that event is captured by the Bokeh server, and I can write the handlers in Python to do things such as modifying the data in ColumnDataSource, for example.
Is this possible? Or is there a better way to accomplish this?
Thanks!
I think the approprate way to achieve what you want is to create a custom widget:
Extending Bokeh Documentation
Custom Widget Example
I do not paste here the complete example because it is too long.
Currently I'm working on Python to automate a powerpoint file. I'm using win32com.client to access the various objects needed. However I haven't been able to find any documentation on chart objects. can someone point me in the right direction.
import win32com.client
PPTApplication = win32com.client.Dispatch("PowerPoint.Application")
PPTApplication.Visible = True
PPTFile = PPTApplication.Presentations.Open("D:\test.pptx")
x=PPTFile.Slides(1).Shapes("Chart1").Chart.ChartData.Workbook.Sheets(1).Range("A1","C13").Value
The code above allows me to access the data for chart1.
How do I access the format axis options????
Or where can I find the documentation for the same.
The PowerPoint Chart object API is documented here:
https://msdn.microsoft.com/EN-US/library/office/ff746468.aspx
The direction you'll want to head is Chart.Axes(), perhaps Chart.Axes(xlValue).
Once you have the axis you want, you have the properties and methods listed here available to you:
https://msdn.microsoft.com/EN-US/library/office/ff745187.aspx
In my experience, it sometimes takes some digging to come up with the path to the right attribute, but that's the general procedure.
Usually when I don't find what I'm looking for I search on 'vba powerpoint chart font color' or whatever specific call I'm looking for and the example VBA code shows the "path" through the object hierarchy to the property I need.
I am working on generating some plots using python, but I am generating these plots using matplotlib which is saved as images. If I create an html page as a report with these plots, they are static images. I cannot zoom in or roll over on the plot to see more detailed or specific information on a time series plot.
My question is how can I make these plots dynamic? Can someone suggest the best way to get started and move forward from there?
You should use some additional libraries to achive your goal.
For example, there some good Python web frameworks wich you can use:
CherryPy - allows you to simply write web-app with Python and you can import your plot there.
Plotly Python API - it would simply generate interactive plot, but store it at Plotly platform, but they provide embeded-code option, so you can use it on your site.
I would suggest Plotly, because it is much simpler, but it depends on your needs.
You will definitely want to do it using javascript. It's by far your best option when it comes to quickly make interactive graphs that you can present to a lot of users. Any of these js libraries will do a great job.
You will then want python to provide the data. Depending on the js library you are using, you might be able to parse data from .json, .csv, etc...
If you don't need the data that makes up your plots to change (with user input, for example), then generating and saving flat files with python and having javascript parsing them from some directory might be just enough.
Otherwise, you want to take a look at a python web framework and use one as backend to serve the plots data by request (in that case .json is probably the right format).
Frameworks like Flask, CherryPy, Pyramid or even web2py might be the easier ones to start with.
I have a project with many scripts using Matplotlib. I'd like to build a web interface for this project.
How do you place a Bokeh chart within a Chameleon template? I'm using Pyramid and the Deform bootstrap if that matters.
Does anyone have a good example out there?
There are several different issues to address here.
If you are truly trying to port a lot of Matplotlib plots into interactive JS, then it's possible that the mpld3 project is a good fit for you. However, you should be aware that by using D3, there will be performance implications, depending on how many points are in your plot. Bokeh also does have basic Matplotlib support now, and will only be getting more. Jake is currently refactoring the mpld3 project into an explicit exporter and then D3 renderer, and we will also be potentially building off of this work for the Bokeh Matplotlib support.
To do this with Bokeh, you can grab the raw HTML for a plot by looking at how e.g. HTMLFileSession.dumps() is implemented: https://github.com/ContinuumIO/bokeh/blob/master/bokeh/session.py#L295. The default template is bokeh/templates/base.html; however, this is a full HTML file, and not a fragment. The dumps() method is pretty straightforward, as is the default template, so you should be able to get what you need from looking at those. Hopefully for the next release, we will have finished out a HTMLFragmentSession which will make it easier to embed.
You want to use plot.create_html_snippet. This function returns the code that you want to appear in the HTML, the function also writes out an embed file.
This is what an embed snippet looks like
<script src="http://localhost:5006/static/dc0c7cfd-e657-4c79-8150-6a66be4dccb8.embed.js" bokeh_plottype="embeddata" bokeh_modelid="dc0c7cfd-e657-4c79-8150-6a66be4dccb8" bokeh_modeltype="Plot" async="true"></script>
the following arguments control how the embed file is written out, and where the js code searches for the embed files.
embed_base_url controls the url path (it can be absolute or relative) that the javascript will search for the embed file in.
embed_save_loc controls the directory that python will write out the embed file in. embed_save_loc isn't necessary when server=True
static_path controls the url path (it can absolute or relative) that the javascript will use to construct URLS for bokeh.js and bokeh.css. It defaults to http://localhost:5006/static/, but could just as easily point to a CDN
When running the bokeh server, navigate to http://localhost:5006/bokeh/generate_embed/static . I think this requires you to be running on master because of a bug.
I hope this helps.