Looking to adjust the right and left margins on shiny-server when working with an .Rmd file instead of ui.R and server.R? The current layout shows excessive margins, consuming half of the window space. Are you wondering if it's possible to tweak the internal css
script or simply include a geometry
option in the markdown header for a quick fix?
https://i.sstatic.net/4wQMw.png
When creating a new Shiny Rmarkdown file in Rstudio, the following sample code is generated:
---
title: "Untitled"
author: "Me"
date: "10/13/2015"
output: html_document
runtime: shiny
---
This R Markdown document integrates interactivity through Shiny. Rather than traditional static reports, interact with documents that allow readers to change assumptions and see instant results.
For more details, visit [Interative Documents](http://rmarkdown.rstudio.com/authoring_shiny.html).
## Inputs and Outputs
Integrate Shiny inputs and outputs into your document, updating outputs as inputs change. This showcases making a standard R plot interactive by using the Shiny `renderPlot` function. Create input widgets with `selectInput` and `sliderInput` functions 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
Embed an entire Shiny application within an R Markdown document using the `shinyAppDir` function. Here's an example embedding a Shiny app located in another directory:
{r, echo=FALSE}
shinyAppDir(
system.file("examples/06_tabsets", package="shiny"),
options=list(
width="100%", height=550
)
)
Adjust the `height` parameter to specify vertical space occupied by the embedded application.
Alternatively, use the `shinyApp` function to define an application inline rather than in an external directory.
Ensure all R code chunks have `echo = FALSE` attribute to prevent rendering alongside the Shiny components.