简体   繁体   English

R Presentation reveal.js:复制文件后未显示背景图像

[英]R Presentation reveal.js: background image not shown after copying file

I have authored an R-presentation using rmarkdown and the reveal.js-framework which works perfectly to a large degree, however, if I copy the output-file (the html-file) to another location, all background images are gone. 我使用rmarkdown和reveal.js-framework编写了一个R-presentation,它在很大程度上完美地工作,但是,如果我将输出文件(html文件)复制到另一个位置,所有背景图像都消失了。 (If I create a copy of the html-file in the same folder it still works). (如果我在同一文件夹中创建html文件的副本,它仍然有效)。 Pictures included using the <img> -tag are still shown. 仍然显示使用<img> -tag包含的<img>

An MWE looks like this: MWE看起来像这样:

presentation.rmd: presentation.rmd:

---
title: "A Test"
author: "tester"
date: "Today"
output:
  revealjs::revealjs_presentation:
    transition: slide
    theme: night
    highlight: espresso
    center: true
    self_contained: true
    reveal_options:
      slideNumber: true
      previewLinks: true
---

# <font color="black">Outline</font> {data-background="kitten.jpg"}

The kitten.jpg -file obviously can be any picture. kitten.jpg -file显然可以是任何图片。 If I open presentation.html (using firefox) everything works, if I copy presentation.html to the desktop and open it again, all background images are gone. 如果我打开presentation.html (使用firefox)一切正常,如果我将presentation.html复制到桌面并再次打开它,所有背景图像都消失了。

Any ideas on what is causing the error and how to solve it? 关于导致错误的原因和解决方法的任何想法?

My system is: 我的系统是:

sessionInfo()

R version 3.2.3 (2015-12-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.1 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=de_DE.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=de_DE.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] rmarkdown_1.0 revealjs_0.7 

loaded via a namespace (and not attached):
[1] magrittr_1.5    htmltools_0.3.5 tools_3.2.3     Rcpp_0.12.7     stringi_1.1.1   stringr_1.1.0  
[7] digest_0.6.10   evaluate_0.9   

A work-around seems to be to use {.slide: id="Sec1"} instead and then adding the background in your custom CSS file 解决方法似乎是使用{.slide: id="Sec1"} ,然后在自定义CSS文件中添加背景

#Sec1 {
  background-image: url(kitten.jpg);
}

The issue is that when you copy presentation.html it is looking for kitten.jpg in the same directory are presentation.html . 问题是当你复制presentation.html它在同一个目录中寻找的是kitten.jpgpresentation.html When I create Rmd documents, I put all my figures in a figures directory, eg figures/kitten.jpg and when I copy the html file, I also copy the figures directory as well. 当我创建Rmd文档时,我将所有数字放在figures目录中,例如figures/kitten.jpg ,当我复制html文件时,我也复制了figures目录。

I'm sure there is a better solution, but this works for me. 我确信有更好的解决方案,但这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM