简体   繁体   English

文本没有出现在 Rmarkdown 中?

[英]Text Not Appearing in Rmarkdown?

I created an html file called "widgets_t.html" (several plotly plots combined together).我创建了一个名为“widgets_t.html”的 html 文件(几个 plotly 图组合在一起)。 Using this tutorial ( https://beta.rstudioconnect.com/jjallaire/htmlwidgets-showcase-storyboard/htmlwidgets-showcase-storyboard.html ) as a demo as well as the answer provided here ( How to create a dropdown menu in flexdashboard? ), I tried to create a Rmarkdown/Flexdashboard document.使用本教程( https://beta.rstudioconnect.com/jjallaire/htmlwidgets-showcase-storyboard/htmlwidgets-showcase-storyboard.html )作为演示以及此处提供的答案( 如何在flexdashboard中创建下拉菜单? ),我尝试创建一个 Rmarkdown/Flexdashboard 文档。 Here is the code that I am using (for this example, I just used the same html input and the same text for brevity purposes ):这是我正在使用的代码(对于这个例子,为了简洁起见,我只是使用了相同的 html 输入和相同的文本):

---
title: "maps"
output:
   flexdashboard::flex_dashboard:
        storyboard: true
        social: menu
        source: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
```

```{css}
.storyboard-nav .sbframelist ul li {
    height: auto;
}
```


Page 1
===================================== 
   
Column {.tabset}
-------------------------------------
   
### Title 1


<object type="text/html" width="1500" height="1500" data="widgets_t.html"></object> 




https://rstudio.github.io/leaflet/

- Interactive panning/zooming

- Compose maps using arbitrary combinations of map tiles, markers, polygons, lines, popups, and GeoJSON.

- Create maps right from the R console or RStudio

- Embed maps in knitr/R Markdown documents and Shiny apps

- Easily render Spatial objects from the sp package, or data frames with latitude/longitude columns

- Use map bounds and mouse events to drive Shiny logic



 
### Title 2  {.tabset .tabset-dropdown}
    

<object type="text/html" width="1500" height="1500" data="widgets_t.html"></object> 




https://rstudio.github.io/leaflet/

- Interactive panning/zooming

- Compose maps using arbitrary combinations of map tiles, markers, polygons, lines, popups, and GeoJSON.

- Create maps right from the R console or RStudio

- Embed maps in knitr/R Markdown documents and Shiny apps

- Easily render Spatial objects from the sp package, or data frames with latitude/longitude columns

- Use map bounds and mouse events to drive Shiny logic


Page 2
=====================================
<object type="text/html" width="1500" height="1500" data="widgets_t.html"></object> 


- Interactive panning/zooming

- Compose maps using arbitrary combinations of map tiles, markers, polygons, lines, popups, and GeoJSON.

- Create maps right from the R console or RStudio

- Embed maps in knitr/R Markdown documents and Shiny apps

- Easily render Spatial objects from the sp package, or data frames with latitude/longitude columns

- Use map bounds and mouse events to drive Shiny logic

Page 3
=====================================
<object type="text/html" width="1500" height="1500" data="widgets_t.html"></object> 


- Interactive panning/zooming

- Compose maps using arbitrary combinations of map tiles, markers, polygons, lines, popups, and GeoJSON.

- Create maps right from the R console or RStudio

- Embed maps in knitr/R Markdown documents and Shiny apps

- Easily render Spatial objects from the sp package, or data frames with latitude/longitude columns

- Use map bounds and mouse events to drive Shiny logic

The above code runs successfully and renders an output in the format I was expecting, but the text (eg " Compose maps using arbitrary combinations of map tiles, markers, polygons, lines, popups, and GeoJSON. " ) is not appearing.上面的代码成功运行并以我期望的格式呈现 output,但文本(例如“ Compose maps using arbitrary combinations of map tiles, markers, polygons, lines, popups, and GeoJSON. ”)没有出现。

  • Does anyone know how I can fix this problem?有谁知道我该如何解决这个问题?

Thank you!谢谢!

PS: Here is an example of "widgets_t.html": PS:这里是一个“widgets_t.html”的例子:

library(plotly)
libtary(htmltools)
library(htmlwidgets)

fig <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length)

doc <- htmltools::tagList(
    div(fig, style = "float:left;width:50%;")
)

htmltools::save_html(html = doc, file = "widgets_t.html")

I'm not sure that I entirely understand what you're looking for.我不确定我是否完全理解您在寻找什么。 You mentioned a tutorial, but the link brings me to a dashboard, not a tutorial.您提到了一个教程,但该链接将我带到了仪表板,而不是教程。 That being said, I'm going to provide my answer and explanation.话虽如此,我将提供我的答案和解释。 You'll just have to let me know if this is what you were looking for.你只需要让我知道这是否是你要找的。

Alright, I'm guessing it is just a typo in your question (I've got plenty of those,) However, the call for the library htmltools , library is spelled wrong.好吧,我猜这只是你的问题中的一个错字(我有很多这样的问题,)但是,对库htmltools的调用, library 拼写错误。 I would hate for that to be the source of your problems.我讨厌这成为你问题的根源。 Although, you indicated it was rendering the graph, so I'm guessing that's not the problem.虽然,你表示它正在渲染图表,所以我猜这不是问题。

I think you want to render this with tab sets, instead of a storyboard.我想你想用标签集而不是 storyboard 来渲染它。

To simplify things for the sake of this answer, I didn't create an external HTML file.为了简化这个答案,我没有创建外部 HTML 文件。 Instead of the height and width you currently have, you're going to use percentages.您将使用百分比,而不是您当前拥有的高度和宽度。 This will maximize the use of space within the parent div .这将最大限度地利用父div中的空间。

So instead of your current setup for <object> , you can use this.因此,您可以使用它,而不是您当前的<object>设置。

<object type="text/html" data="widgets_t.html" style="width:100%; height:100%;" /> 

I'm not sure why you chose to go with embedding HTML instead of rendering it directly.我不确定您为什么选择 go 嵌入 HTML 而不是直接渲染它。 If there is a problem, that's a likely source of contention.如果有问题,那很可能是争论的根源。 For example, widgets have a default of 100% width and 400px height...Yuck, When you render them inline.例如,小部件的默认值为 100% 宽度和 400px 高度......哎呀,当你内联渲染它们时。 they just seem to 'listen' better.他们似乎“听”得更好。 (Just my opinion!) (只是我的观点!)

I added styling you don't need, in addition to styling you do need.除了您确实需要的样式之外,我还添加了您不需要的样式。 Things like border, padding, background color, and line height can all be dropped without any consequences to the organization.边框、填充、背景颜色和行高等内容都可以删除,而不会对组织造成任何后果。 I just thought it improved the appearance.我只是认为它改善了外观。

You should also notice that I gave 70% of the width to the plot and 30% to the text column.您还应该注意到,我将 70% 的宽度分配给 plot 并将 30% 分配给文本列。 You can definitely adjust these values, but they should total 100% between the two.您绝对可以调整这些值,但两者之间的总和应为 100%。

<style>
.pics {
  float:left;
  width:70%; 
  height:90vh;
}
.words {
  float:right; 
  width:30%; 
  height:90vh;
  padding: 10px; 
  border-style: outset; 
  border-width: 1px; 
  background-color: #fdfdfd;
  line-height: 2em; /* this is double-spacing lines of text the html way */
}
</style>

Before each set of object tags, you'll include <div><div class="pics"> .在每组object标签之前,您将包含<div><div class="pics"> For example, the first one will look like this:例如,第一个看起来像这样:

Page 1
===================================== 
   
Column {.tabset}
-------------------------------------
   
### Title 1
    
<div>
<div class="pics">

Between your object calls and the bullets, you'll use </div><div class="words"> .在您的 object 调用和项目符号之间,您将使用</div><div class="words"> The first placement looks like this:第一个位置如下所示:

</div>
<div class="words">

https://rstudio.github.io/leaflet/

- Interactive panning/zooming
- Compose maps using arbitrary combinations of map tiles, markers, polygons, lines, popups, and GeoJSON.
- Create maps right from the R console or RStudio

After the bullet points, you have to close out the div tags.在要点之后,您必须关闭div标签。 That's going to look like this.看起来像这样。

- Embed maps in knitr/R Markdown documents and Shiny apps
- Easily render Spatial objects from the sp package, or data frames with latitude/longitude columns
- Use map bounds and mouse events to drive Shiny logic

</div></div>

在此处输入图像描述

在此处输入图像描述

I tested here and the text "compose maps.. etc" appears perfectly, shows on the first page and others.我在这里进行了测试,文本“撰写地图..等”完美显示,显示在第一页和其他页面上。 Can you give more details?你能提供更多细节吗? (page? just this line? sessionInfo(), etc) (页面?只是这一行?sessionInfo()等)

screenshot截屏

EDIT编辑

I didn't understand the question right earlier.我之前没有理解这个问题。

You have to edit the HTML proportions and adjust your text accordingly.您必须编辑 HTML 比例并相应地调整您的文本。 example:例子:

First you should change image proportions首先你应该改变图像比例

<object type="text/html" width="1000" height="500" data="widgets_t.html"></object> 

Second, embebed the next text in a HTML ><二、在 HTML 中嵌入下一个文本 ><

<html>
- Compose maps using arbitrary combinations of map tiles, markers, polygons, lines, popups, and GeoJSON.

- Create maps right from the R console or RStudio

- Embed maps in knitr/R Markdown documents and Shiny apps

- Easily render Spatial objects from the sp package, or data frames with latitude/longitude columns

- Use map bounds and mouse events to drive Shiny logic      
    </html>

The result: new screenshot结果:新的截图

Using the (amazing) code provided by @Kat, here is the answer in one chunk:使用@Kat 提供的(惊人的)代码,这里是一大块的答案:

---
title: "maps"
output:
   flexdashboard::flex_dashboard:
        storyboard: true
        social: menu
        source: embed
---

<style>
.pics {
  float:left;
  width:70%; 
  height:90vh;
}
.words {
  float:right; 
  width:30%; 
  height:90vh;
  padding: 10px; 
  border-style: outset; 
  border-width: 1px; 
  background-color: #fdfdfd;
  line-height: 2em; /* this is double-spacing lines of text the html way */
}
</style>




```{r setup, include=FALSE}
library(flexdashboard)
```

```{css}
.storyboard-nav .sbframelist ul li {
    height: auto;
}
```


Page 1
===================================== 
   
Column {.tabset}
-------------------------------------
   
### Title 1


   
<div>
<div class="pics">

<object type="text/html" data="widgets_t.html" style="width:100%; height:100%;" /> 

</div>
<div class="words">

https://rstudio.github.io/leaflet/

- Interactive panning/zooming

- Compose maps using arbitrary combinations of map tiles, markers, polygons, lines, popups, and GeoJSON.

- Create maps right from the R console or RStudio

- Embed maps in knitr/R Markdown documents and Shiny apps

- Easily render Spatial objects from the sp package, or data frames with latitude/longitude columns

- Use map bounds and mouse events to drive Shiny logic


</div></div>

 
### Title 2  {.tabset .tabset-dropdown}
    

<div>
<div class="pics">


<object type="text/html" data="widgets_t.html" style="width:100%; height:100%;" /> 

</div>
<div class="words">



https://rstudio.github.io/leaflet/

- Interactive panning/zooming

- Compose maps using arbitrary combinations of map tiles, markers, polygons, lines, popups, and GeoJSON.

- Create maps right from the R console or RStudio

- Embed maps in knitr/R Markdown documents and Shiny apps

- Easily render Spatial objects from the sp package, or data frames with latitude/longitude columns

- Use map bounds and mouse events to drive Shiny logic

</div></div>



Page 2
=====================================
<div>
<div class="pics">


<object type="text/html" data="widgets_t.html" style="width:100%; height:100%;" /> 

</div>
<div class="words">


- Interactive panning/zooming

- Compose maps using arbitrary combinations of map tiles, markers, polygons, lines, popups, and GeoJSON.

- Create maps right from the R console or RStudio

- Embed maps in knitr/R Markdown documents and Shiny apps

- Easily render Spatial objects from the sp package, or data frames with latitude/longitude columns

- Use map bounds and mouse events to drive Shiny logic

</div></div>


Page 3
=====================================


<div>
<div class="pics">

<object type="text/html" data="widgets_t.html" style="width:100%; height:100%;" /> 

</div>
<div class="words">


- Interactive panning/zooming

- Compose maps using arbitrary combinations of map tiles, markers, polygons, lines, popups, and GeoJSON.

- Create maps right from the R console or RStudio

- Embed maps in knitr/R Markdown documents and Shiny apps

- Easily render Spatial objects from the sp package, or data frames with latitude/longitude columns

- Use map bounds and mouse events to drive Shiny logic

</div></div>

Thanks @Kat!谢谢@Kat!

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

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