Back
Featured image of post What works here?

What works here?

still need to bring older posts here!

Details - Summary

Click Here!

And hidden details will show

They can also contain code

Click Here!

toydf <- data.frame(foo = 1:10, bar = 20:29)
base::summary(toydf)
##       foo             bar       
##  Min.   : 1.00   Min.   :20.00  
##  1st Qu.: 3.25   1st Qu.:22.25  
##  Median : 5.50   Median :24.50  
##  Mean   : 5.50   Mean   :24.50  
##  3rd Qu.: 7.75   3rd Qu.:26.75  
##  Max.   :10.00   Max.   :29.00

They can also contain plots

Click Here!

hist(mtcars$mpg)

Tabs

There does not seem to be native support, as in normal rmarkdown fo example.

https://github.com/rstudio/blogdown/issues/69 https://github.com/yihui/hugo-prose/issues/25

But completely css tabs seems to work.

<h1>Orange</h1>
<p>The orange (specifically, the sweet orange) is the fruit of the citrus species Citrus × sinensis in the family Rutaceae</p>
<p>The fruit of the Citrus × sinensis is considered a sweet orange, whereas the fruit of the Citrus × aurantium is considered a bitter orange. The sweet orange reproduces asexually (apomixis through nucellar embryony); varieties of sweet orange arise through mutations.</p>
<h1>Tangerine</h1>
<p>The tangerine (Citrus tangerina) is an orange-colored citrus fruit that is closely related to, or possibly a type of, mandarin orange (Citrus reticulata).</p>
<p>The name was first used for fruit coming from Tangier, Morocco, described as a mandarin variety. Under the Tanaka classification system, Citrus tangerina is considered a separate species.</p>
<h1>Clemantine</h1>
<p>A clementine (Citrus ×clementina) is a hybrid between a mandarin orange and a sweet orange, so named in 1902. The exterior is a deep orange colour with a smooth, glossy appearance. Clementines can be separated into 7 to 14 segments. Similarly to tangerines, they tend to be easy to peel.</p>

Good!, verbose as hell, but, it works.

toydf <- data.frame(foo = 1:10, bar = 20:29)
base::summary(toydf)
##       foo             bar       
##  Min.   : 1.00   Min.   :20.00  
##  1st Qu.: 3.25   1st Qu.:22.25  
##  Median : 5.50   Median :24.50  
##  Mean   : 5.50   Mean   :24.50  
##  3rd Qu.: 7.75   3rd Qu.:26.75  
##  Max.   :10.00   Max.   :29.00
hist(mtcars$mpg)

# Example from plotly page https://plotly.com/r/bubble-charts/
library(plotly)

data <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/school_earnings.csv")

data$State <- as.factor(c(
  'Massachusetts', 'California', 'Massachusetts', 'Pennsylvania', 'New Jersey', 
  'Illinois', 'Washington DC', 'Massachusetts', 'Connecticut', 'New York', 
  'North Carolina', 'New Hampshire', 'New York', 'Indiana', 'New York', 
  'Michigan', 'Rhode Island', 'California', 'Georgia', 'California', 
  'California'
))

fig <- plot_ly(
  data, x = ~Women, y = ~Men, text = ~School, type = 'scatter', 
  mode = 'markers', size = ~Gap, color = ~State, colors = 'Paired', 
  marker = list(opacity = 0.5, sizemode = 'diameter')
)
fig <- fig %>% layout(title = 'Gender Gap in Earnings per University',
         xaxis = list(showgrid = FALSE),
         yaxis = list(showgrid = FALSE),
         showlegend = FALSE)

fig

Far from perfect, but it works.

NOTE: I don’t know what exactly is going on. Locally, the interactive plot works. But netlify’s build fails due to plugin error. The cuprit seems to be plotly javascript main assets (plotly-latest.mim.js); as soon as you commit this, netlify’s build fail. It even fails without this, but linking it via CDN. (which is actually a TODO, to do that for all interactive stuff).There should be some weird interaction between plotly and other things in this post, because plotly works in netlify in other posts in this blog. But I am not in the mood of finding out more.

Options

Remember to set this option blogdown.generator.server = TRUE. From the blogdown slides:

Hugo is fast. You are likely to be satisfied by the speed of the live preview via Serve Site (or blogdown::serve_site()).

But live preview can be (a lot) faster. It may just take 10 milliseconds to re-render the site, if you install the processx package, and set an option in R:

options(blogdown.generator.server = TRUE)

By default, blogdown renders the full site to disk on changes and reload it in your browser, which may take one or two seconds. If you set this option, blogdown will take advantage of Hugo’s own server (via the command hugo server), which is much faster.

options(
  blogdown.generator.server = TRUE,
  blogdown.hugo.server = c('-D', '-F', '--navigateToChanged')
)
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy