Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.6k views
in Technique[技术] by (71.8m points)

Unable to embed Bookdown site in R Shiny app

I have a Bookdown site that I would like to embed in an R Shiny app, however I am having an issue where only the top toolbar is rendering correctly. I am using a basic Bookdown template and rendering the site using the gitbook option, then trying to embed the html files into the R Shiny app, as shown in my code below.

When displayed in fullscreen, only the top toolbar is visible: Fullscreen image of R Shiny app with only the top toolbar of the Bookdown site visible

When the window is made smaller, it becomes apparent that the body of the content is being rendered, but in an extremely small box up near the top: Image of R Shiny app not in fullscreen with the top toolbar of the Bookdown site visible as well as a sliver of the body content in a small box with a scrollbar

It's unclear why this is happening and I've tried this with larger R Shiny apps as well as the minimalist example below. I initially tried this using a larger Bookdown site and then with smaller examples including the single-page site in the reprex here. What is causing this odd rendering and is it possible to fix this within a Shiny app environment?

server.R file

library(shiny)
library(htmltools)

shinyServer(function(input, output, session) {

  output$ui <- renderUI({
    htmltools::includeHTML("./www/index.html")
  })

})

ui.R file

library(shiny)

shinyUI(
  uiOutput("ui")
)

_bookdown.yml

book_filename: "Bookdown Reprex"
output_dir: www
delete_merged_file: true
language:
  label:
    fig: "FIGURE "
    tab: "TABLE "
  ui:
    chapter_name: ""

_output.yml

bookdown::pdf_book:
  keep_tex: yes
  latex_engine: xelatex
  pandoc_args: --top-level-division=chapter
  toc_depth: 2
  toc_unnumbered: no
bookdown::gitbook:
  css: css/style.css
  split_by: chapter
  lib_dir: book_assets
  config:
    toc:
      collapse: chapter
    download: pdf
    sharing: no

index.Rmd

---
title: "Bookdown Reprex"
date: "`r Sys.Date()`"
fontsize: 11pt
geometry: margin=1in
mainfont: FreeSans
site: bookdown::bookdown_site
always_allow_html: yes
colorlinks: yes
---

Introduction
============

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, 
PDF, and MS Word documents. For more details on using R Markdown see 
<http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content 
as well as the output of any embedded R code chunks within the document. You can embed an 
R code chunk like this:

```{r cars}
summary(cars)
```

style.css

p.caption{
  color: #777;
  margin-top: 10px;
}
p code {
  white-space: inherit;
}
pre {
  word-break: normal;
  word-wrap: normal;
}
pre code {
  white-space: inherit;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...