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

Don't fetch widget dependencies if no yaml file exists #277

Closed
wants to merge 3 commits into from

Conversation

cpsievert
Copy link
Collaborator

As @ramnathv points out in #259 (comment), this makes getDependency() only return the htmlwidgets.js dependency if no yaml config file exists.

This should fix #179 and also makes #259 obsolete

@jjallaire
Copy link
Collaborator

LGTM. @ramnathv ?

@jcheng5
Copy link
Collaborator

jcheng5 commented Jun 2, 2017

Looks like we lose bindingDep too in this case--did you intend that?

@cpsievert
Copy link
Collaborator Author

cpsievert commented Jun 2, 2017

Looks like we lose bindingDep too in this case--did you intend that?

Yes, if we were to include bindingDep at this stage, I don't think it would be possible to place other assets before the binding, which doesn't seem right for most cases.

I guess this would introduce breaking changes for widgets that don't have no yaml and no external dependencies (just the binding), but that seems like a fairly small set of packages, and a fix would be easy (declare your binding in the yaml).

@ramnathv
Copy link
Owner

ramnathv commented Jun 6, 2017

Apologies for a delayed response on this. @cpsievert on the issue of including the binding dependency, can you throw some light on some use cases. Are there any reasons for wanting to include the binding dependency at a position other than right at the end or at the top?

@cpsievert
Copy link
Collaborator Author

I've added a better comment about the early return in 1c1ace4

I need this for a few different things in plotly. For instance, our TypedArray polyfill and MathJaX extras (if included) need to appear before the plotly.js bundle/binding. Furthermore, I'd like to determine whether these (and other) dependencies are really needed at print time, rather than always including them.

@ramnathv
Copy link
Owner

ramnathv commented Jun 6, 2017

Thanks @cpsievert. This makes sense. Can we also add some documentation around this? You can use the motivating use case for this feature to explain how to use it.

@cpsievert
Copy link
Collaborator Author

Sure, feel free to suggest a place to document.

Before we move forward though, I'm not quite sure this is working in a shiny context. Here is a MRE

devtools::install_github('ropensci/plotly')

library(shiny)
library(plotly)

ui <- fluidPage(
  plotlyOutput("p")
)

server <- function(input, output, ...) {
  output$p <- renderPlotly({
    qplot(1:10)
  })
}

shinyApp(ui, server)

Nothing appears, and if you look in <head>, none of the plotly dependencies are included, which is odd, especially considering if you set a breakpoint here and call renderFunc() the dependencies seem to be there...any ideas what might be happening?

@cpsievert
Copy link
Collaborator Author

FWIW, it seems as though ShinyBinding.renderValue isn't being called, which is probably the source of the problem

@cpsievert
Copy link
Collaborator Author

cpsievert commented Jun 6, 2017

Huh, adding the yaml back (as done in plotly/plotly.R@45933a5) causes ShinyBinding.renderValue to be called, which fixes the rendering problem in shiny, but reintroduces the dependency ordering problem.

@cpsievert
Copy link
Collaborator Author

cpsievert commented Jun 6, 2017

Having a closer look at htmlwidgets.js, it seems as though there is a general assumption that widget binding(s) are known (i.e., registered) before any messages are received from the shiny server. That is why I was seeing the issue outlined above.

Perhaps it'd be possible to dynamically register htmlwidget bindings in shiny, but that will likely require significant revisions in htmlwidgets.js...

@jcheng5
Copy link
Collaborator

jcheng5 commented Jun 14, 2017

Why can't the bindingDep be the first thing that's loaded in your case? I.e. don't lose the bindingDep in the no-yaml case. When the binding script executes it should generally just be registering closures, not actually using d3 or whatever...?

@jcheng5
Copy link
Collaborator

jcheng5 commented Jun 14, 2017

For instance, our TypedArray polyfill and MathJaX extras (if included) need to appear before the plotly.js bundle/binding.

This could cause an issue if you have two plotly plots on the same Shiny page that have different dynamic requirements. How bad is it if those extras are loaded after the plotly bundle?

@cpsievert
Copy link
Collaborator Author

why can't the bindingDep be the first thing that's loaded in your case?

Sorry, I should've mentioned that it can (at least it seems to work fine for me at the moment). I'll close the issue (at least for now) since I'm not sure if these proposed changes are a good idea anymore.

How bad is it if those extras are loaded after the plotly bundle?

Bad, especially for MathJaX, but perhaps I could export some helpers to insert dependencies in the UI (e.g., use_mathjax()/use_typedarray())

@cpsievert cpsievert closed this Jun 14, 2017
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

Successfully merging this pull request may close these issues.

Dependency ordering
4 participants