juba / robservable

Observable notebooks as R htmlwidgets
https://juba.github.io/robservable/
163 stars 11 forks source link

Better default width and height handling #19

Closed juba closed 4 years ago

juba commented 4 years ago

Not totally sure about this one yet but after a bit of tinkering I think it may be the best default.

If the new R update_width argument is TRUE (which is the default), and input$width is not defined, then input$width is replaced by the actual width of the widget root HTML element. The same for height. The replacement is done both at widget creation and when resizing.

width will always be an actual notebook value, as it is either defined in the notebook or by the Observable standard library. This is not the case of height, but we try to update it anyway (just displaying a JS warning if the variable doesn't exist).

The aim of this is to provide, as much as possible, convenient out of the box behavior when robservable is used inside Rmarkdown documents or Shiny applications.

timelyportfolio commented 4 years ago

@juba I really like these changes. I tried to test as best I could but not sure we can ever capture every potential combination/use. Are there any Observablehq notebooks that you like best to demonstrate the effect of the change? Maybe we should include a couple as examples. I'll keep trying to find some. Most of the @d3 notebooks use viewBox which masks the change.

If you are looking for approval, you have mine :)

juba commented 4 years ago

Thanks for your approval ! :)

I think there are several cases of examples :

I think there may be other cases, such as when width and height are explicitly defined. I didn't check with this kind of notebook yet...