-
Notifications
You must be signed in to change notification settings - Fork 127
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
A proposal for HTML Widgets #87
base: main
Are you sure you want to change the base?
Conversation
…orkidle methods for chrome_print
@@ -0,0 +1,139 @@ | |||
// An auto-scaling iframe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I used iFrame Resizer in Distill and was quite happy with it: http://davidjbradshaw.github.io/iframe-resizer/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was unaware of iFrame Resizer. This looks awesome! I will give it a try. Thanks!
…(I suscept that the cookie is not associated with the top frame)
Merge branch 'master' into iframed-widgets # Conflicts: # inst/resources/js/config.js
Merge branch 'master' into iframed-widgets # Conflicts: # DESCRIPTION # inst/resources/js/config.js
@RLesur, I appreciate the effort you are putting into supporting widgets in rmarkdown. I'm trying this on plotly, and while it is much closer (something actually appears), it is offset and mis-scaled.
--- title: Sample `pagedown` Report output: pagedown::html_paged: css: ["default-page", "default"] toc: false number_sections: false params: dat: !r NULL bins: !r NULL --- ```{r setup, echo = FALSE, include = FALSE} stopifnot(!is.null(params$dat), !is.null(params$bins)) library(plotly) plot_base <- function(x, b) { bins <- seq(min(x), max(x), length.out = b + 1) hist(x, breaks = bins, col = 'darkgray', border = 'white') } plot_plotly <- function(x, b) { bins <- list(start = min(x), end = max(x), size = (max(x) - min(x)) / b ) plot_ly(x = ~x, type = "histogram", xbins = bins) } ``` # Inputs Input data: - Number of bins: `r params$bins` - Data sample: `r format(head(params$dat), digits=3)` # Plots A base plot: ```{r plot1, echo = FALSE} plot_base(params$dat, params$bins) ``` A second plot: ```{r plot2, echo = FALSE} plot_plotly(params$dat, params$bins) ``` On rendering, it shows (opposing pages):
|
Thank you, @r2evans for your support! I really appreciate because from the beginning of pagedown this feature is the most difficult one (I spent so much hours on that). In the current state of this PR, there is no default styling for widgets. Your example has highlighted for me the need for such a default styling. In your example, you can add these chunk options, for instance:
|
I was hoping that chunk style options might mitigate it, but had not completely investigated it. Those options do in fact get it closer to "norm", now just aesthetic tweaks (e.g., font size). Thank you! |
@medewitt I've seen (https://github.com/rstudio/pagedown/network) you're improving the branch. Do not hesitate to propose modifications. I'm interested in feedbacks/collaborations on this topic. |
@RLesur will do. We're tweaking the scaling for different htmlwidgets. Your scaling works beautifully for |
@medewitt Great news! I will resolve the current git conflicts. |
Merge branch 'master' into iframed-widgets # Conflicts: # DESCRIPTION # R/paged.R # inst/resources/js/chrome_print.js # inst/resources/js/config.js
This is a really cool addition, I hope that it's pulled into the main release soon. Thank you for adding this! I think this has the potential to really transform my workflow. I could create an interactive report that I can share easily and anyone can print it into a nice pdf/printout when then want to. I had the best luck doing CSS styling outside of the code chunk. But that may be a limitation of my CSS skills :). Here's a MWE in case it benefits anyone.
|
Hey @RLesur , great proposal, I'm really looking forward to this feature! It would be fantastic to be able to output plots from |
Merge branch 'master' into iframed-widgets # Conflicts: # DESCRIPTION # R/paged.R # inst/resources/js/config.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry it took so long to get back to this PR. My main question is about as_html_attrs()
. All the rest of suggestions are optional; feel free to accept or discard. Thanks!
as_html_attrs = function(string) { | ||
doc = xml2::read_html(sprintf('<p %s>', string)) | ||
node = xml2::xml_find_first(doc, './/p') | ||
xml2::xml_attrs(node) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an interesting hack. Since eventually you'd need a list, perhaps we could document it that out.extra
is expected to be a list? So that we don't need to introduce a new dependency or use a hack.
I can also support list values in knitr. It is easier to go from a list to a string than the other way around, e.g., I can generate id="foo" class="bar"
from out.extra = list(id = "foo", class = "bar")
in knitr.
BTW, what was the use case on your mind for out.extra
? If you don't have a significant use case yet, perhaps we can support this option in the future as users request for it.
Same as others, this functionnality would really fill a gap for me ! After a few tests with the code below :
thanks anyway, test.R :
testPageDown2.Rmd :
|
Co-authored-by: Yihui Xie <[email protected]>
Co-authored-by: Yihui Xie <[email protected]>
Co-authored-by: Yihui Xie <[email protected]>
Co-authored-by: Yihui Xie <[email protected]>
Co-authored-by: Yihui Xie <[email protected]>
Co-authored-by: Yihui Xie <[email protected]>
this addresses rstudio#87 (comment)
Here's a first draft for #58
After hundreds of trials and errors, I'm quite happy with these first results.
I spent most of the time on the HTML/JS implementation: here, the strategy is to use responsive iframes (these are scaled iframes embedded in containers with
overflow: hidden
). In order to synchronize the rendering process with both Paged.js andchrome_print()
, I needed to enhance these responsive iframes with methods/events/promises: HTML Custom Element was the perfect tool. I've not worked on crosstalk but I guess this could be feasible.I'm not yet satisfied by the R part: I'm not sure to have done the right choices. Since knitr/rmarkdown/htmltools/htmlwidgets is your garden, I let you decide how to implement this part.
I think this proposal could be extended to
browsable
objects or urls. There are still some features to implement (captions, aspect ratios...). But I would prefer having your review first.