如何减少闪亮的交互式rmarkdown利润?

时间:2015-10-13 23:30:55

标签: html css r shiny r-markdown

当发光服务器看到.Rmd文件而不是ui.R和server.R时,有没有办法减少左右边距?如下所示,窗口的近一半是左右边距。有没有办法修改内部css脚本来进行更改,还是通过在markdown标题中添加geometry选项来实现更简单的解决方案?

enter image description here

以下是在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.

2 个答案:

答案 0 :(得分:6)

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

等CSS规则

答案 1 :(得分:0)

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

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