【问题标题】:How to reduce shiny interactive rmarkdown margins?如何减少闪亮的交互式 rmarkdown 边距?
【发布时间】:2016-01-11 21:19:55
【问题描述】:

当shiny-server 看到.Rmd 文件而不是ui.R 和server.R 时,有什么办法可以减少左右边距?正如您在下面看到的,几乎一半的窗口是左右边距。有没有办法修改内部的 css 脚本来进行更改,或者是否有更简单的解决方案,在 markdown 标头中添加 geometry 选项?

这是我在 Rstudio 中创建新的 Shiny Rmarkdown 文件时生成的示例代码:

---
title: "Untitled"
author: "Me"
date: "10/13/2015"
output: html_document
runtime: shiny
---

This R Markdown document is made interactive using Shiny. Unlike the more traditional workflow of creating static reports, you can now create documents that allow your readers to change the assumptions underlying your analysis and see the results immediately. 

To learn more, see [Interative Documents](http://rmarkdown.rstudio.com/authoring_shiny.html).

## Inputs and Outputs

You can embed Shiny inputs and outputs in your document. Outputs are automatically updated whenever inputs change.  This demonstrates how a standard R plot can be made interactive by wrapping it in the Shiny `renderPlot` function. The `selectInput` and `sliderInput` functions create the input widgets used to drive the plot.

```{r, echo=FALSE}
inputPanel(
  selectInput("n_breaks", label = "Number of bins:",
              choices = c(10, 20, 35, 50), selected = 20),

  sliderInput("bw_adjust", label = "Bandwidth adjustment:",
              min = 0.2, max = 2, value = 1, step = 0.2)
)

renderPlot({
  hist(faithful$eruptions, probability = TRUE, breaks = as.numeric(input$n_breaks),
       xlab = "Duration (minutes)", main = "Geyser eruption duration")

  dens <- density(faithful$eruptions, adjust = input$bw_adjust)
  lines(dens, col = "blue")
})
```

## Embedded Application

It's also possible to embed an entire Shiny application within an R Markdown document using the `shinyAppDir` function. This example embeds a Shiny application located in another directory:

```{r, echo=FALSE}
shinyAppDir(
  system.file("examples/06_tabsets", package="shiny"),
  options=list(
    width="100%", height=550
  )
)
```

Note the use of the `height` parameter to determine how much vertical space the embedded application should occupy.

You can also use the `shinyApp` function to define an application inline rather then in an external directory.

In all of R code chunks above the `echo = FALSE` attribute is used. This is to prevent the R code within the chunk from rendering in the document alongside the Shiny components.

【问题讨论】:

    标签: html css r shiny r-markdown


    【解决方案1】:

    查看由 Rmd 文件生成的 HTML 后,看起来主要内容位于类 main-content 的 div 下,并且它具有 max-width 属性。查看rmarkdown 源代码,我相信这可能会发生here。尝试添加像div.main-container { max-width: inherit; }这样的css规则

    【讨论】:

    • 这是一个很好的答案 - 它有效。您可以类似地指定确切的宽度,例如添加 &lt;style&gt; div.main-container { max-width: 1600px; } &lt;/style&gt;
    【解决方案2】:

    上面的 CSS 更改对我不起作用,因为我在 RStudio 中从 Rmd 渲染 HTML 时遇到了同样的问题,但这确实有效。在 Rmd 中的 YAML 之后添加:

    <style>
    .main-container {
        max-width: 940px;
        margin-left: 0;
        margin-right: auto;
    }
    </style>
    

    【讨论】:

      猜你喜欢
      • 2019-07-01
      • 2017-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      • 2020-12-01
      • 2015-12-06
      相关资源
      最近更新 更多