Open sdementen opened 3 years ago
Can you insert the script using the app.get_asset_url
function and the local assets functionality? Note that this requires the staticfiles finders to be configured.
I have replaced
app.scripts.append_script(dict(external_url=app.get_asset_static_url("script.js")))
by
app.scripts.append_script(dict(external_url=app.get_asset_url("script.js")))
as you asked and I get the same error message (I had already configured my django to use locally served files by following https://django-plotly-dash.readthedocs.io/en/latest/local_assets.html#local-assets).
This issue is in https://github.com/plotly/dash/blob/dev/dash/resources.py#L46 where specifying an "external_url" while serving locally is not supported.
Unfortunately look like external url doesn't work when serve_locally is true, so i go workaround I try to explain my solution for serve font-awesome locally, i hope this could help you:
app.css.append_css(
{
'asset_path': STATIC_URL + 'font-awesome/css/all.css',
'filepath': STATIC_ROOT + 'font-awesome/css/all.css', # don't forget collectstatic files
})
app.scripts.append_script(
{
'asset_path': STATIC_URL + 'font-awesome/js/all.js',
'filepath': STATIC_ROOT + 'font-awesome/js/all.js',
})
also i'll unsuccessfully try to setup asset path, but can't find the way using the view
static files finders were configured but it is doesn't help
so i write new hardcoded redirect rule in urls.py
re_path(r'^static/dpd/assets/my_app/my_view/(?P
it work, but is the way make it more flexible?
I have just commented the second part of the condition in https://github.com/plotly/dash/blob/dev/dash/resources.py#L46 and got it working with external_url but patching dash like this doesn't sound clean.
In the exception message, Dash explicitly tells to use external_scripts
so I guess the cleaner way is for django-plotly-dash to support it.
with #312 , I can write:
app = DjangoDash(
"myapp",
external_scripts=[
static_asset_path(__name__, "my-local-script.js"),
],
external_stylesheets=[
"https://unpkg.com/tailwindcss@1.9.6/dist/tailwind.min.css",
static_asset_path(__name__,"my-local-css.css"),
dbc.themes.BOOTSTRAP,
],
)
and it works
@sdementen can this issue now be closed?
Maybe still a need to update the docs around the use of append_script?
To add a local script, I am using
app.scripts.append_script(dict(external_url=app.get_asset_static_url("script.js")))
with serve_locally=True and I get the warningwith the file not being included in the html via the
{% plotly_footer %}
.It appears that the append_script approach is to be replaced by the use of external_scripts in Dash. Does django-plotly-dash support this ?