-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML5 templates? #44
Comments
Since Plotly dash is built on flask, any chance jinja2 templating will be
in the works?
On Sun, Jun 25, 2017 at 11:59 PM Zafarali Ahmed ***@***.***> wrote:
Most of the examples I have seen rely on building the entire HTML front
end via the python interface. Is there a way to use a pre-defined HTML5
template and substitute the graphs in there?
This way one can prototype the interface independently of the dash logic.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#44>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF1yH8Nbtf1nOwkXmyHkKPkKitQBZIzrks5sHyyegaJpZM4OE2k0>
.
--
Cedric Yau
cedricyau@gmail.com
|
There isn't any plan to do this right now. While the Writing web markup with Python classes may seem pretty odd at first, but there are actually a lot of really great things that you can do it with it:
The "logic" of a Dash app is separated from the initial "view" of the app already. The app's |
Closing this for now since it's not on the immediate roadmap, but certainly always happy to hear more thoughts or feedback :) |
Another note - one could also write a Dash component that takes a raw HTML string and renders it with React's
and then if you wanted Jinja templating, you could run your string through Jinja before passing into the component, like:
Here's how to create custom components in Dash: https://plot.ly/dash/plugins. |
I would argue its extremely useful to be able to generate HTML using other means than just Apart from these aesthetic considerations, TL;DR I do think it should be possible to plug in HTML code generated elsewhere into Dash. Seamless support for |
I ran into this myself on a personal project where I wanted to render HTML from a third-party source and converting it to the I have created a I still stand by the belief that
For example, conditional formatting a table to create a component like Further, you can easily re-use components that you have created since it's just regular Python!
As far as I'm aware, this is just related to Dash not currently supporting |
@chriddyp, if I understand you correctly, what you say about My point, however, is that writing plain HTML is way too verbose with Imagine a complex web app where you'd like to use a few I'm not too familiar with React, but let me summarize why I think
After brief googling I came across the project aknuds1/html-to-react which seems like it could be solution to this problem. I can imagine the following workflow (I'm going to use
As a result, the
Unless I'm missing something, as a result of this we'd get the same React DOM structure as we currently do. We satisfy both initial requirements - we still have just one top-level React component, and all plain HTML elements are part of React system, so could be easily interacted with from Dash Python callbacks. Only other thing I can think of which is currently done on Python side is validation of all component ids between registered callbacks and layout. While no longer possible to do on the Python side (unless you parse HTML to DOM with e.g. I've described what happens with initial layout, but the exact same thing could be applied to Dash callbacks which return With this approach you no longer need Finally, not related to the above - for those who are happy to use |
I wrote something to address this very same concern: It is just a proof-of-concept that could benefit a lot from the ideas above. My original idea was to be able to inject Dash components into Jinja templates but I ended up specifying my own sort of "templating format". |
I totally agree with @nirvana-msu. Yes, we do have dash-html-components, which is pretty handy at creating html components. But what about html structure? As far as I can see, most of the show and tell projects are merely "stacks" of html components. How do we control the structure of our application? In the layout page of your tutorial, I can only find out a layout that is controlled by
I am new to this, maybe I am on the wrong track, but I don't know how else I can do it. |
Same problem, When we want a full fledged application. We need a lot of html. |
Here's my attempt at turning an HTML-like language with embedded Python into calls to Dash constructors: https://github.com/jkseppan/htexpr/ With that you can write @ssword's example like this: import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
from htexpr import compile
app = dash.Dash(__name__, external_stylesheets=[
'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css'
], external_scripts=[
'https://code.jquery.com/jquery-3.3.1.slim.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js',
'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js'
])
app.layout = compile("""
<div class='content'>
<div class='container-fluid'>
<div class='row'>
<div class='col-lg-3 col-md-6 col-sm-6'>
<div class='card card-stats'>
<div class='card-header' data-background-color='orange'>
<i class='fa fa-file-alt' />
</div>
<div class='card-body'>
<div style={'font-family':'Roboto','font-weight':'bold'}>
<h3 class='title'><b>Textual Analysis</b></h3>
<hr />
<div class='alert alert-info alert-with-icon' data-notify='container'>
<i class='fa fa-check-square' data-notify='icon' />
<button class='close'
data-dismiss='alert'
aria-label='Close'
type='button'>
<i class='material-icons'>close</i>
</button>
<span data-notify='message'>
<b>Check to select all items</b>
</span>
</div>
<div class='col-lg-3 col-md-6 col-sm-6' style={'background-color': 'yellow'}>
<h4 class='card-title'>
<i class='fa fa-hospital fa-w-14 fa-1x grape5' data-notify='icon' />
Facilities
</h4>
</div>
<Dropdown
options=[
{'label': 'New York City', 'value': 'NYC'},
{'label': 'Montréal', 'value': 'MTL'},
{'label': 'San Francisco', 'value': 'SF'}
]
multi={True}
value='MTL' />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
""").run()
if __name__ == '__main__':
app.run_server(debug=True) This is almost HTML, but you have to close all tags (but Forum post: https://community.plot.ly/t/htexpr-write-dash-layouts-in-html-syntax/21669 |
Great work @jkseppan, really helpful for me since writing HTML is much faster for me. |
* commit generated files to the repo - This is another sanity check for prerelease checks - Enables users to install directly from GitHub. For Python users, installing from PyPI is still the recommended way to install the package * let eslint ignore generated bundles
* commit generated files to the repo - This is another sanity check for prerelease checks - Enables users to install directly from GitHub. For Python users, installing from PyPI is still the recommended way to install the package * let eslint ignore generated bundles
* commit generated files to the repo - This is another sanity check for prerelease checks - Enables users to install directly from GitHub. For Python users, installing from PyPI is still the recommended way to install the package * let eslint ignore generated bundles
Most of the examples I have seen rely on building the entire HTML front end via the python interface. Is there a way to use a pre-defined HTML5 template and substitute the graphs in there?
This way one can prototype the interface independently of the dash logic.
The text was updated successfully, but these errors were encountered: