文本没有出现在 Rmarkdown 中?

sta*_*oob 4 html text r data-visualization r-markdown

我创建了一个名为“widgets_t.html”的 html 文件(几个情节图组合在一起)。使用本教程(https://beta.rstudioconnect.com/jjallaire/htmlwidgets-showcase-storyboard/htmlwidgets-showcase-storyboard.html)作为演示以及此处提供的答案(如何在 flexdashboard 中创建下拉菜单?),我尝试创建一个 Rmarkdown/Flexdashboard 文档。这是我正在使用的代码(在本例中,为了简洁起见,我只是使用了相同的 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
Run Code Online (Sandbox Code Playgroud)

上面的代码成功运行并以我期望的格式呈现输出,但文本(例如“ Compose maps using arbitrary combinations of map tiles, markers, polygons, lines, popups, and GeoJSON.”)没有出现。

  • 有谁知道我该如何解决这个问题?

谢谢你!

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")
Run Code Online (Sandbox Code Playgroud)

Kat*_*Kat 6

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. 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.

To simplify things for the sake of this answer, I didn't create an external HTML file. 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.

So instead of your current setup for <object>, you can use this.

<object type="text/html" data="widgets_t.html" style="width:100%; height:100%;" /> 
Run Code Online (Sandbox Code Playgroud)

I'm not sure why you chose to go with embedding HTML instead of rendering it directly. 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, 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. You can definitely adjust these values, but they should total 100% between the two.

<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>
Run Code Online (Sandbox Code Playgroud)

Before each set of object tags, you'll include <div><div class="pics">. For example, the first one will look like this:

Page 1
===================================== 
   
Column {.tabset}
-------------------------------------
   
### Title 1
    
<div>
<div class="pics">
Run Code Online (Sandbox Code Playgroud)

Between your object calls and the bullets, you'll use </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
Run Code Online (Sandbox Code Playgroud)

After the bullet points, you have to close out the div tags. 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>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在此输入图像描述