Skip to content
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

is there a way to load static file like png or ttf in a custom dash component plugin package? #96

Closed
pingf opened this issue Jul 24, 2017 · 10 comments

Comments

@pingf
Copy link

pingf commented Jul 24, 2017

I'm writting my own dash components on top of dash & react-semantic-ui.
just find that it's hard to use the icon in dash, cause most react lib pack png files(and many others like ttf) for the icon.

@chriddyp
Copy link
Member

Hm good question. Does the solution in #71 work for you?

@chriddyp
Copy link
Member

Er, it wouldn't really if you're writing your own bundle. The Dash component bundles only include CSS and JS bundles (see e.g. https://github.com/plotly/dash-core-components/blob/master/dash_core_components/__init__.py#L15-L43).

We could also include a way to specify the image assets of the bundle / package as well.

@chriddyp chriddyp changed the title is there a way to load static file like png or ttf? is there a way to load static file like png or ttf in a custom dash component plugin package? Jul 24, 2017
@pingf
Copy link
Author

pingf commented Jul 25, 2017

yep, i've find that there are only two kinds of dist config(js and css) which makes hard to write components like icon on top of other react library.
for now , I'm writting my own components using react-semantic-ui, for the icon part, I have to use icons in awesome font(just include the awesome css and put the fa-xxx in the class).

@yunake
Copy link

yunake commented Aug 16, 2017

@chriddyp are there any plans to look into this? would you accept a PR that implements it? i need to serve map files for my components and an assortment of static resources such as fonts and icons.

@chriddyp
Copy link
Member

@yunake - I'm not planning on looking into this in the immediate future. I would accept a PR that would add this. This will likely be added to the https://github.com/plotly/dash-components-archetype repository. If possible, a little write up (in a github issue) on the general approach of how this would be accomplished would be really helpful for me and others before the PR gets submitted.

@yunake
Copy link

yunake commented Aug 17, 2017

Great!
I was thinking of creating a mechanism similar to _css_dist/Resources(), but special-cased for directories. For the sake of clean user interface, I think it would be preferable to have user specify his static artefact directory in his __init__.py, and have us hook it into flask.send_from_directory, under a component-specific url just like current resources. The downside is that the client code now needs to know the component name to figure out which URIs to generate to reach the resources, but I think this is a reasonable requirement, since these components would be tied to Dash anyway. What do you think?
I have no idea when I will work on this, for now I have a work-around with a custom flask route that handles everything for me, but as we expand our collection of modules, we certainly want to establish clear relationships between the resources.

@yunake
Copy link

yunake commented Aug 17, 2017

actually, since packages can be egg files and even pex, send_from_directory won't cut it - something like this might be more appropriate, with a pregenerated set of files+urls (for security) - this is what i currently use in my workaround:

from pkg_resources import resource_stream
flask.send_file(
        resource_stream(component_name, os.path.join(static_dir, resource_url)),
        attachment_filename=os.path.basename(resource_url)
    )

@nicolaskruchten
Copy link
Contributor

I'm also hitting the need for something like this. I want to add static files to a component, in this case I want to add a JS file to dash_renderer that's not to be loaded via index every time.

HammadTheOne pushed a commit to HammadTheOne/dash that referenced this issue May 22, 2021
HammadTheOne pushed a commit to HammadTheOne/dash that referenced this issue May 28, 2021
HammadTheOne pushed a commit to HammadTheOne/dash that referenced this issue May 28, 2021
@zeusttu
Copy link

zeusttu commented May 28, 2021

Also hitting this issue when trying to add an icon to a search box. Since it's a component library which is only used internally by one project, I can work around it by duplicating the icon in the project's assets folder, but that's really an ugly workaround and also not feasible for everyone I think.

HammadTheOne pushed a commit that referenced this issue Jul 23, 2021
Companion to PR #96 -- forgot to regen
@gvwilson
Copy link
Contributor

gvwilson commented Jun 3, 2024

Hi - this issue has been sitting for a while, so as part of our effort to tidy up our public repositories I'm going to close it. If it's still a concern, we'd be grateful if you could open a new issue (with a short reproducible example if appropriate) so that we can add it to our stack. Cheers - @gvwilson

@gvwilson gvwilson closed this as completed Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants