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

helper function for files produced with html_print #10

Closed
timelyportfolio opened this issue Apr 8, 2015 · 8 comments
Closed

helper function for files produced with html_print #10

timelyportfolio opened this issue Apr 8, 2015 · 8 comments

Comments

@timelyportfolio
Copy link
Contributor

I think a very useful helper function with webshot would be something that provides the valid url for a local file created with htmltools::html_print. I doubt this works on non-Windows but something like this might be very helpful especially with htmlwidgets (see ramnathv/htmlwidgets#95).

library(leaflet)
library(htmltools)
library(webshot)

tagList(
  tags$h1( 'Leaflet Map for Screenshot' )
  ,leaflet() %>% addTiles() %>% fitBounds(0, 40, 10, 50)
) %>%
  html_print %>%
  # get forward slash on windows
  normalizePath(.,winslash="/") %>%
  # replace drive:/ with drive:// so C:/ becomes C://
  gsub(x=.,pattern = ":/",replacement="://") %>%
  # appends file:/// to make valid uri
  paste0("file:///",.) %>%
  # screenshot it for lots of good reasons
  webshot( file = "stream_screen.png", delay = 3 )

image

@timelyportfolio timelyportfolio changed the title helper function for files produced with html_print helper function for files produced with html_print Apr 8, 2015
@timelyportfolio
Copy link
Contributor Author

@wch is this worth exploring/demonstrating in webshot or would it fit better in htmlwidgets?

@yihui
Copy link
Collaborator

yihui commented Mar 3, 2016

This has been (almost) done in the current master branch of yihui/knitr. Simply try an arbitrary widget in R Markdown, and compile it to a non-HTML output format:

leaflet() %>% addTiles() %>% fitBounds(0, 40, 10, 50)

I have not supported arbitrary HTML objects (such as tagList()), though. See more info at https://github.com/yihui/knitr/blob/master/NEWS.md

@yihui
Copy link
Collaborator

yihui commented Mar 3, 2016

Oh I forgot to mention that requires this branch of htmlwidgets: ramnathv/htmlwidgets#191

@timelyportfolio
Copy link
Contributor Author

Great, I'll check it out there and close this issue here. I only used tagList to ease html_print. Thanks!

@wch
Copy link
Owner

wch commented Mar 3, 2016

I can see how this might be useful outside of knitr as well.

@timelyportfolio I think that this functionality would conceptually be a nice fit for inclusion in htmlwidgets. However, because webshot has some unusual external dependencies, it could make sense to include that functionality in the webshot package itself.

@yihui
Copy link
Collaborator

yihui commented Mar 3, 2016

Definitely agree this can be useful outside knitr.

@timelyportfolio
Copy link
Contributor Author

Ok, happy to work something up, but know quest for CRAN might push it to next release. Let me know if you want to squeeze it in and I'll be glad to work on it.

@wch
Copy link
Owner

wch commented Mar 3, 2016

Yup, I just submitted to CRAN so it would have to be for the next version.
:)

On Thu, Mar 3, 2016 at 4:44 PM, timelyportfolio [email protected]
wrote:

Ok, happy to work something up, but know quest for CRAN might push it to
next release. Let me know if you want to squeeze it in and I'll be glad to
work on it.


Reply to this email directly or view it on GitHub
#10 (comment).

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

3 participants