Giter VIP home page Giter VIP logo

msmbstyle's Introduction

msmbstyle

The msmbstyle package provides an alternative design for HTML books produced using the R package bookdown. The layout was developed to closely match an existing publication produced using Sweave and LaTeX. The general structure is heavily influenced by the handout design of Edward Tufte, with figures and annotations appearing in the margin alongside the main text, and much of the document conversion/creation is actually carried out by the tufte package. msmbstyle provides some additional modifications to the overall layout of the book.

You can view a simple example of the HTML produced by msmbstyle at https://www-huber.embl.de/users/msmith/msmbstyle/, and the R Markdown documents used to generate this are present in the /inst/extdata/ folder of this package

A example of a complete book generated using msmbstyle can be found at Modern Statistics for Modern Biology by S. Holmes & W. Huber.

msmbstyle vs tufte styling

A (probably incomplete) list of the layout differences between an HTML book produced by msmbstyle and the default options in tufte:

  • Book title and author names listed in a header bar at the top of each page.
  • Document navigation provided by drop-down menu in the top right of each page.
    • One entry per chapter.
    • The current chapter has sections listed too.
  • Sans serif font for the main text (currently using Source Sans Pro)
  • Defines additional document sections (currently Questions & Solutions) that can be referenced in text, and have their visibility toggled within the final document
  • Keeps default width of code blocks when vertically aligned with margin figures.
  • Provides CSS support to place tables in the margin along with figures and notes.

Alternate branches

The grid-layout branch uses Bootstrap to provide an alternative approach to arranging the content into columns. An example can be seen at https://www.huber.embl.de/users/msmith/msmbstyle/bootstrap/

Acknowledgments

Funding

Funding for development of this package and the surrounding efforts directed towards the creation of the online version of Modern Statistics for Modern Biology is provided by the German Network for Bioinformatics Infrastructure

msmbstyle's People

Contributors

grimbough avatar lgatto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

msmbstyle's Issues

edit_link not found

Very impressive package! I'm particularly interested in the bootstrap development version. I followed the instructions here, but I get the following error:

Error in get(name, envir = asNamespace(pkg), inherits = FALSE) : 
  object 'edit_link' not found
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.14

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
[1] ggplot2_3.0.0   msmbstyle_0.0.3 bookdown_0.8   

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0       compiler_3.5.0   pillar_1.2.3    
 [4] plyr_1.8.4       highr_0.7        bindr_0.1.1     
 [7] tools_3.5.0      digest_0.6.15    packrat_0.4.9-3 
[10] lattice_0.20-38  nlme_3.1-137     evaluate_0.12   
[13] tibble_1.4.2     gtable_0.2.0     mgcv_1.8-23     
[16] pkgconfig_2.0.2  rlang_0.3.0.1    Matrix_1.2-14   
[19] rstudioapi_0.7   yaml_2.2.0       xfun_0.4        
[22] bindrcpp_0.2.2   withr_2.1.2      stringr_1.3.1   
[25] dplyr_0.7.8      xml2_1.2.0       knitr_1.20      
[28] grid_3.5.0       tidyselect_0.2.5 tufte_0.4       
[31] glue_1.3.0       R6_2.3.0         rmarkdown_1.11.3
[34] reshape2_1.4.3   purrr_0.2.5      magrittr_1.5    
[37] codetools_0.2-15 scales_1.0.0     htmltools_0.3.6 
[40] assertthat_0.2.0 colorspace_1.3-2 labeling_0.3    
[43] stringi_1.2.4    lazyeval_0.2.1   munsell_0.5.0   

Appendix support

I'm trying to use your terrific package to generate a book with an Appendix, using this bookdown feature to number the Appendices separately (A, B, etc). My testing stub is below.

The trouble is that the appendices are numbered incorrectly in the TOC dropdown, although their section titles are correct on the page.

image

I'm using the latest version of msmbstyle 0.0.15 installed from github this morning.

---
site: bookdown::bookdown_site
title: "Foobar: A Novel"
author: "Tim Herzog"
date: "`r Sys.Date()`"
output:
  bookdown::pdf_book:
    includes:
      in_header: preamble.tex
    latex_engine: xelatex
    # citation_package: natbib
    keep_tex: no
    toc: no
    title: no
  bookdown::html_book:
    toc: true
    number_sections: true
  msmbstyle::msmb_html_book:
    toc: true
    number_sections: true
documentclass: book
classoption:
 - openright
 - oneside
# bibliography: [book.bib, packages.bib]
# biblio-style: apalike
# link-citations: yes
---

# Introduction

Yada yada yada

# Chapter Two #

Dark and stormy night

# (APPENDIX) Appendix {-}

# List of Preferred Holloween Candies

* Recess peanut butter cups
* Snickers
* M&Ms

# Shopping List

* Toilet paper
* Paint brushes

Acknowledgement of msmbstyle and author

In my forthcoming Writing for Conservation guide, I acknowledge msmbstyle in the following way, in the Preface (note link through to the github page):

Screenshot from 2019-05-14 19-14-33

I would also be happy to acknowledge the author by name, if you feel that is appropriate. Could you kindly let me know?

With thanks.

References in margin and as a final chapter

I really like to have references in the margin, it makes for a better reading experience. It can however also be useful to have all references in their own References chapter.

Is it possible to automatically generate such a chapter at the end in addition to the margin refs?

(PART) or (PART\*) does not work for grid style

The problem mentioned in Parts and TOC links #22 still exists for the grid style. When using (PART*), not only there was an empty page created with the title (PART*) part title. The characters (PART*) also shows in the TOC. It seems a problem when build_chapter is called.

Can you please resolve this problem so that it only shows the part title as a unlinked list in TOC as a separator for chapters?

Thank you!

levels in table of contents

Is it possible to limit the levels of the table of contents? I tried setting toc_depth: 1, but my TOC still displays 2 levels. I'd prefer to show only 1 level, and I have the particular challenge that some of my second level headings are set to not get section numbers (e.g., ## Heading 2{-}) and appear as NA in the TOC

Broken links

The links to the examples and book are broken.

Margin figures text size

Using the code below the figure that appears in the margin has an overly small font size. Do you know if Is this something that is a result of the data/plot, or the way that msmbstyle is doing the formatting?

# If tidyverse package not installed in RStudio, remove '#' from next line 
# The read_csv comamnd is part of the Tidyverse package readr
# install.packages("tidyverse")
library(tidyverse)  

# Read the data
data <- read_csv("country,number_of_species
                 Ecuador,96
                 Peru,87
                 Colombia,52
                 Bolivia,43
                 Venezuela,18
                 Argentina,7")

# Default ggplot figure style
# Note that the package is called ggplot2 but the command is 'ggplot'
ggplot(data, aes(country, number_of_species)) + # Specify x first, then y
  geom_bar(stat = "identity") + # Plot type
  theme_gray()

With grateful thanks.

grid-layout problem previewing book

Thank you for the msmb style and the grid-style. I am experimenting with moving my book project to the grid-style (there are many long pages, and the chapter navigation is vital for a good user experience, and grid-style has it!).

When I try to preview the sample grid-style book, I receive the following error:

Quitting from lines 29-63 (_main.Rmd) Error: 'margin_note' is not an exported object from 'namespace:msmbstyle'

Many thanks for any thoughts on this!

No Section TOC in the left margin

I really like the msmb style, which gives the book a fresh and dynamic look.

Unfortunately, I cannot get the Section-TOC in the left margin to work.

Even the example in the ext data does not seem to generate the left margin TOC.

Without the sections in the left margin, the useability of this cool style is severely reduced.

Was anybody able to get the left margin section-TOC to work?

Thanks!

table row stripes from kableExtra?

Is it possible to use row stripes from kableExtra in this template? I have not been able to get the color to appear when compiling in bookdown, but it works with a regular Rmarkdown document.

library(knitr)
library(kableExtra)
dt <- mtcars[1:5, 1:6]
kable(dt) %>%
  kable_styling(bootstrap_options = c("striped", "hover"))

Parts and TOC links

I'm having trouble with links to parts in the TOC.

To reproduce, go here and choose Module 1 from the TOC. You should get a 404 page. It's trying to go to:

https://read.themethodsection.com/module-1-getting-started-with-global-health-research.html1-getting-started-with-global-health-research

The link in the TOC doubles up the file name.

If you back up and go to Chapter 1, scroll to the bottom, and click Next, you will get to the proper Module 1 page: https://read.themethodsection.com/module-1-getting-started-with-global-health-research.html

I tried using # (PART\*) my title and # (PART) my title as Yihui recommends, but "(PART)" is copied over into the TOC.

Here's my repo showing this approach. Unless I'm doing something wrong, I think there is an issue in creating the TOC link.

Is there a plan to support Quarto?

I love this template and use in my old R Markdown project. But I am trying to use Quarto instead for it is more modern design.

So is there a pla to support this amazing html template in Quarto? or if I want to do this, where can I start?

Several msmbstyle tweaks available

Hello,

thank you very much for msmbstyle! You can add my book The Effect as an example of an msmbstyle-themed book if you like.

I made a few tweaks that I'm not sure you'd want to incorporate into the main package (although who knows), but someone using msmbstyle may want to be aware of. I've made them available at TheEffectStyle.

These include:

  • Centering numbered equations in the text column rather than centering them across the page (this one you may want to fix/incorporate as it seems wrong, although probably in the package itself other than through CSS)
  • Moving the chapter-select dropdown to instead be an always-on navbar on the left hand side.
  • Restarting the sidenote numbering with each chapter

I'm also working on trying to incorporate a searchbar like some other bookdown styles have, which I'll also post on the repo once I figure it out, although that one will probably also involve a fork of the msmbstyle repo since I'll need to add the search bar as an HTML element.

Installation failure for msmbstyle

I'm trying to install the msmbstyle package using the commands recommended:

install.packages("remotes")
remotes::install_github("grimbough/msmbstyle")

and I'm met the the error and I'm dead in the water. I'm in Windows 10, R v 3.6.2, RStudio v 1.2.5033.

Downloading GitHub repo grimbough/msmbstyle@master
✓ checking for file 'C:\Users\David Stevens\AppData\Local\Temp\Rtmp44RC2N\remotes4d45b0ad94\grimbough-msmbstyle-1560d18/DESCRIPTION' ...
─ preparing 'msmbstyle':
✓ checking DESCRIPTION meta-information ...
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
─ building 'msmbstyle_0.0.12.tar.gz'

Installing package into ‘C:/Users/David Stevens/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)

  • installing source package 'msmbstyle' ...
    ** using staged installation
    ** R
    ** inst
    ** byte-compile and prepare package for lazy loading
    ARGUMENT 'Stevens\AppData\Local\Temp\RtmpSeaFGH\Rin78c68ea455e' ignored

Error: unexpected symbol in "Microsoft Windows"
Execution halted
ERROR: lazy loading failed for package 'msmbstyle'

  • removing 'C:/Users/David Stevens/Documents/R/win-library/3.6/msmbstyle'
    Error: Failed to install 'msmbstyle' from GitHub:
    (converted from warning) installation of package ‘C:/Users/David Stevens/AppData/Local/Temp/Rtmp44RC2N/file4d47bc8758c/msmbstyle_0.0.12.tar.gz’ had non-zero exit status

Any ideas what's going wrong?

Best
David Stevens

Add text to the footer

Is there a way to define footer text in the YAML? The Modern Statistics example has additional footer text.

Screenshot 2019-04-10 11 23 20

If not in the YAML, what's the best way to add text? I see that the existing "Page built" text is defined in msmb_html.R

'<p class="build-date">Page built: ', as.character(Sys.Date()), '</p>',

Dumb question, but would I need to fork this repo and add the text I want to this file, or is there a simpler solution with the existing package?

Header and title section colours

I was wondering if you were interested is setting the header and title section colour (#1881c2) as a global variable? This would allow a user to relatively simply customise it for different books/projects.

I have experimented with:

:root {
  --main-bg-color: #2aa0ea;
}

and, in msmb.css

h1 {
  color: var(--main-bg-color);
  width: 55%;
  border-bottom-color: var(--main-bg-color);
  border-bottom-style: solid;
  padding-bottom: 0.5rem;
}

h2 {
  color: var(--main-bg-color);
  border-bottom-color: var(--main-bg-color);
  border-bottom-style: solid;
  width: 55%;
  padding-bottom: 0.5rem;
  margin-top: 3em;
  font-weight: bold;
}

h3 {
  color: var(--main-bg-color);
  font-size: 1.5rem;
}
[...]

Formatting of tables

Following this suggestion ##15 I can use this code

library(knitr)
library(kableExtra)
options(kableExtra.html.bsTable = T)
options(knitr.kable.NA = '')
data_sources <- read_csv("tables/data_sources.csv")
kable(data_sources) %>%
  kable_styling() %>% 
  row_spec(0, bold = F) %>% 
  row_spec(1, background = "#eff9fe") %>% 
  row_spec(6, background = "#eff9fe") %>% 
  row_spec(10, background = "#eff9fe") %>% 
  row_spec(15, background = "#eff9fe")

to style a table (although row_spec(0, bold = F) does not prevent bolding of the header row).

But the table is placed across the whole page (i.e. tab.margin = FALSE has no effect) and a citation of the usual form (Table @ref(tab:data-sources)) does not link to the table.

Is there a solution to this problem?

Thanks!

Inserting URL to a video

I would like to include links to some instructional videos on my youtube panel. The only way I have found to do it is with the vembedr package, viz:

vembedr::embed_youtube(rep("_FeR6EFXnck"))

Although this works, it does not allow resizing, placing in the margin, or other modifications, and one cannot use a figure label. In the absence of any alternative, this at least works. This is what I would like to be able to do:

knitr::include_url("https://www.youtube.com/embed/9bZkp7q19f0")

(see rstudio/bookdown#92) but it doesn't do anything.

Do you have any ideas?

With grateful thanks.

Including link + icon in heder bar

I have completed two short books using msmbstyle. These books are going to be included in the new website of the conservation science journal of which I am the editor. To be able to incorporate the books into our own site we need to add an icon and link in the header bar of each, so that a reader can return to the main site from the books.

However, I cannot figure out how to do this!

If you have any suggestions, I would be exceedingly grateful. Thank you.

Blockquote

Yes, I agree. At the moment msmbstyle is just piggy-backing on the tufte package, and that seems to define block quote as a simple indentation, which doesn't seem in the spirit of how blockquote is supposed to be used. I'll have a look at some examples and maybe refine it a bit, but I'll try to keep the side notes inline when I do!

Feel free to ask questions / make suggestions about the CSS, it's not my forte either. Glad you're finding the package useful, and I'd be very excited to see it used elsewhere in the wild.

Originally posted by @grimbough in #8 (comment)

position of margin table

Many thanks for such a great package!

I noticed that the position of the margin table is not aligned with the main text where it was referenced, especially when echo = TRUE is set in knitr trunk option. If the code is long, the table will be put way too low. Is there anything we can do to move it up?

Use your example at https://www-huber.embl.de/users/msmith/msmbstyle/tables.html#tab:margin-table, can we move the margin table 1.2 up to the same height of the sentence "You can also include tables in the margin column as in Table 1.2, with the caption above" ? or at least to the same height of the first line of the echoed code (HIV <- data.frame(Patient = ... ) ?

References in the margins

I am working on two different computers. The margin_references: TRUE output is set in my index.Rmd and the references appear in margins only on my laptop only, not on my desktop.
I assume this is because of a missing (system?) dependency but I fail to identify which one.

Any help much appreciated.

Footnote on list item formatted incorrectly

With msmbstyle, if one adds a footnote to a list item the footnote in the right hand column is aligned too far to the left (i.e. it does not left align with other items in the column).

This code illustrates the problem:

`- Literature citations do not have matching references, and vice versa.^[Solution: use a [reference manager][Reference management].]

Literature citations and references are not in the journal's preferred format.^[Solution: use a [reference manager][Reference management].] `

Would it be possible for this to be fixed?

With grateful thanks!

font size and a few other small things in grid-layout

Loving how the html is rendered in the grid-layout branch. A few questions:

  1. What would be the correct custom css style to change the font size and style for the body copy? That would be the text within sections and rows, I think. I tried changing body but that changed the section TOC.

  2. Is it possible to put figure numbers with the captions in margin notes?

  3. How did you "turn off" footnote numbers in the margin notes?

knitr::include_url

I'm trying to embed a webpage in a book as shown here, but the frame does not appear in the html output. Any ideas?

```{r test, echo=FALSE}
knitr::include_app("https://yihui.shinyapps.io/miniUI/", 
  height = "600px")
```
```{r test, echo=FALSE}
knitr::include_url("https://github.com/grimbough/msmbstyle", 
  height = "600px")
```

grid style problem with {-}

With the grid-style I have noticed that inclusion of {-} after a heading, to remove the chapter number, viz

Introduction {-}

results in an incorrectly formatted header.

Thanks.

msmbstyle 0.0.9 + bookdown 0.1 problems

Good day

I have updated to msmbstyle 0.0.9 with bookdown 0.1 and there are two problems (illustrated here with msmbstyle-master):

  1. The header is not present:
    Screenshot from 2019-05-11 05-51-59

  2. Code chunks run in to the margin (i.e. the bottom slider does not appear):
    Screenshot from 2019-05-11 05-52-36

Would it be possible for you to look into these matters? Our new website (with a book prepared in msmbstyle embedded) is due to go live in the next 1-2 weeks and it would be very helpful if you could find time to look at this).

With grateful thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.