-
Notifications
You must be signed in to change notification settings - Fork 240
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
Make tutorials printable #465
Comments
Here's an intermediate solution using CSS and print @media print {
.topicsContainer,
.topicActions,
.exerciseActions .skip {
display: none;
}
.topics .tutorialTitle,
.topics .section.level2,
.topics .section.level3:not(.hide) {
display: block;
}
.topics {
width: 100%;
}
.tutorial-exercise, .tutorial-question {
page-break-inside: avoid;
}
.section.level3.done h3 {
padding-left: 0;
background-image: none;
}
.topics .showSkip .exerciseActions::before {
content: "Topic not yet completed...";
font-style: italic;
}
} You can insert this CSS into a single tutorial with a CSS markdown chunk
or you can store it in a file, say ---
output:
learnr::tutorial:
css: print.css
--- CaveatsGenerally, printing from the web works best on Chrome, but Safari and Firefox also fare well. Here's an example of a complete tutorial printed from Safari: example-printed-tutorial.pdf The user's content will appear in the printed version, and fortunately learnr saves the past tutorial state so a user could return to a completed tutorial and print their work. They will, however, need to visit each topic within the tutorial for all of the content to be populated, so it's probably best to nudge users to print at the end of the tutorial. The CSS above will also hide sections that haven't been shown yet if you've enabled Let me know if this works for you and we'll consider incorporating this into the package. |
Thank you for the insight! I've run this with two tutorials and two browsers and it seems to be performing well enough on both Chrome and Firefox (I'll ask my colleague to try it on her Mac next week). The only glitch is that answers and dataframes are lacking their colors, but personally that seems fine. The "Topic not yet completed..." warning is excellent. As you already indicated, providing the option to print is not strictly necessary, but it provides users with more options to review their material, and saves our server some load (especially during the exam)! For potential incorporation in learnr: finding and using each browsers "print..." option is finicky (it took me embarrassingly long find out how to trigger the CSS code :p ). |
Thankyou for this which seemed like it could solve a use-case we have. We provide learnr tutorials on shinyapps and want to be able to provide a backup pdf option for learners who have unreliable internet. I tried following your suggestion of putting into print.css. But printing the shinyapps page from Chrome just results in the first topic (afrimapr/afrilearnr#10) rather than all topics as you show in your example. This message in the chrome developer window suggests possible source of problem. Apologies I am not well versed in web development, css etc. Suggestions welcome. Thanks. |
No idea what the error is! I'll post the code that worked for us below. We tested this on Rstudio and Rstudio Server.
|
Thanks @gadenbuie @siebrenf, eventually I got this to do what I wanted by just using the css chunk in each Rmd see afrimapr/afrilearnr#10 (comment) |
We're developing a set of tutorials for a remote course. At the end of the course, there will be some form of open exam, during which students can bring their own notes. It would be nice for students to save their (entire) current tutorial to PDF/static HTML.
Notes:
Knitr seems to allow for this in pure markdown, JavaScript seems to allow for this for Shiny, but I haven't been able to get this to work in a learnr tutorial. Please note that I barely understand anything related to js.
Here's the list of methods which don't seem to work:
The best I've come up with is an actionButton to trigger a js chunk with some non-functioning code to save to PDF.
Related SO posts:
rmarkdown cache management from shiny_prerenderd to static runtime
Export Shiny page to PDF
Is there a “Save Page As PDF” for Shiny app?
Is it possible to save HTML page as PDF using JavaScript or jquery?
Generate pdf from HTML in div using Javascript
Is there a way to use a Javascript package in R?
The text was updated successfully, but these errors were encountered: