-
Notifications
You must be signed in to change notification settings - Fork 480
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
User-defined RequireJS deps #1247
Comments
Is requirejs a hard dependency? I think (from my googling around) that it makes it hard(er)to include plotlyjs plots in documentation. Without requirejs a simple raw HTML block like this:
would just work (tm), but currently I'm getting "Plotly not defined errors". I think that even with the API in this issue implemented it would still be pretty complicated (based on me not being able to figure out how to make it work by tweaking files manually). Note that this is a sort-of follow up to #1424, where you helped me include the raw HTML in the page, which worked. |
It's not a hard requirement -- you can always drop If you want to do it with RequireJS and use it that way, I think you have to somehow make sure that you have the |
Yes, that's what I did, but I got the "not defined" error. Unfortunately I don't know enough about JS to figure out how to handle What I meant was: is requirejs a hard requirement for Documenter? |
When you're using
I am not sure I quite understand the question. If you mean whether we could drop RequireJS from Documenter completely, then technically, sure, that would be doable. At the time when I implemented it, I was hoping it would help simplify the handling of JS dependencies. It has its pros, but it also complicates things sometimes. |
The plot does work with a simple html example, and it works in Franklin as well. As a test I also (just now) removed the requirejs script header tag and it did load the plot correctly.
Yes, that is what I meant. Obviously I understand that it would be work. I can't really weigh the pros and cons myself but I suppose the above is a data point. |
Could you post the simple HTML example here? |
Sure, this is pretty much the simplest you can get: <html>
<head>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<div id="7979e646-13e6-4f44-8d32-d8effc3816df" style="height: 500; width: 100%;"></div>
<script>
Plotly.newPlot("7979e646-13e6-4f44-8d32-d8effc3816df", [{"x": [1, 2, 3], "y": [3, 1, 6]}], {},)
</script>
</body>
</html> |
As I'm sure you'll be testing, adding requirejs does breaks the example, though only if it is added before plotly. This might be a stopgap solution. |
Following this SO answer, it is possible to get Plotly working if you load it via RequireJS. I.e. something like this will work: require(['plotly'], function(plotly) {
console.log(plotly); // Object {Lib: Object, util: Object...}
plotly.newPlot("7979e646-13e6-4f44-8d32-d8effc3816df", [{"x": [1, 2, 3], "y": [3, 1, 6]}], {},)
}); (It does not look like there is any actual need to load D3 or jQuery as deps as the SO answer suggests.. I guess Plotly maybe bundles them nowadays?) However, as far as I can tell, this does mean that all the plotting code would have to be in the I did find an old issue that looks related requirejs/requirejs#947. Essentially it looks like the only thing we could do is load Plotly with a |
Yes.
Why not simply put all the user dependencies before requirejs? It seems like if they are loaded after there's a chance they wouldn't work anyway. |
It may well be the better default, I don't actually have a strong opinion. But since you can have these weird interactions between the libraries, it can be that there are scripts that have issues if they are before RequireJS. Ultimately, allowing the user to control this might be good. Also, if it's customizable, we could also allow putting scripts at the very end of the HTML file, which can avoid issues with the page not loading if the script is not accessible for some reason or takes a long time to load. |
I opened a dedicated issue about the location of the |
Hey I'd like to use Literate.jl to generate markdown for Documenter.jl for documentation of a package, and I'd like it to use HTML to represent PlotlyJS.jl plots. (See the linked issue just above.) Currently, the default |
See fredrikekre/Literate.jl#126 (comment) for a way to include PlotlyJS plots. |
Documenter's generated HTML output uses RequireJS to load JS deps mostly. #1092 generalized the internals so that the RequireJS initialization code in
documenter.js
gets generated dynamically on each build. The next step is to allow the users to add their own libraries and snippets too.Note: as a workaround, you may be able to include a library/script with independently of RequireJS with
assets
. But this does not always work, as the module loading can clash (also happens with Plotly).Potential implementation:
Documenter.jl/src/Writers/HTMLWriter.jl
Lines 560 to 571 in 39da9a0
HTML
'sassets
keyword. AnyRemoteLibrary
andSnippet
objects (fromJSDependencies
) could be filtered out based on their type and looped over during the construction of theRequireJS
object.The text was updated successfully, but these errors were encountered: