Kewitschka
Kewitschka

Reputation: 1671

R markdown output size

I want to generate a R markdown page with an interactive shiny app. It works fine but the output is in a really small area with scrollbars. I want to get rid of the scrollbars and show the 2 figures with full width and height without scrollbars. How can I achieve that?

I have already tried:

options(width = 800)

Currently it looks like this: enter image description here

    ---
title: "Spielercluster"
output: html_document
runtime: shiny
---
```{r,echo=FALSE}
library(ggplot2)
library(shiny)

data<-read.csv2('data.csv',header=T,sep=",") 
rawData<-read.csv2('rawData.csv',header=T,sep=",")
cluster<-read.csv2('cluster.csv',header=T,sep=",")
colors<-c("green","red","black")

ui<-fluidPage(plotOutput("plot1", hover = "plot_hover"),
              plotOutput("plot2", hover = "plot_hover"),
              verbatimTextOutput("info")
)

server <- function(input, output) {

  output$plot1 <- renderPlot({
ggplot(rawData, aes(koerpergewicht, groesse, color =  factor(data$gruppe))) +
          geom_point() + labs(title = paste(nlevels(factor(colors))))+geom_point(size=8)+geom_text(aes(label=position),vjust=-1.5)+scale_color_manual(name = "Gruppe",
  labels = c("1 schwer", "2 leicht","3 Zwischengruppe"),
  values = c(rgb(0.9725490196078431,0.4627450980392157,0.4274509803921569,1),rgb(0,0.7294117647058824,0.2196078431372549,1),rgb(0.3803921568627451,0.6117647058823529,1,1)))+ggtitle("Original")
  })

  output$plot2 <- renderPlot({
ggplot(rawData, aes(koerpergewicht, groesse, color =  factor(cluster$x))) +
          geom_point() + labs(title = paste(nlevels(factor(colors))))+geom_point(size=8)+geom_text(aes(label=position),vjust=-1.5)+scale_color_manual(name = "Gruppe",
  labels = c("1 schwer", "2 leicht","3 Zwischengruppe"),
  values = c(rgb(0.9725490196078431,0.4627450980392157,0.4274509803921569,1),rgb(0,0.7294117647058824,0.2196078431372549,1),rgb(0.3803921568627451,0.6117647058823529,1,1)))+ggtitle("Berechnet")
  })


  output$info <- renderPrint({
    nearPoints(rawData, input$plot_hover, , threshold = 10, maxpoints = 1,
               addDist = TRUE)
  })
}

shinyApp(ui, server)
```

Upvotes: 8

Views: 4680

Answers (5)

Kode Charlie
Kode Charlie

Reputation: 1489

I'm on R Shiny Server Pro 1.5.11.994, and CentOs 7.5.

After dabbling with server options, figure dimensions (Eg, fig.width, or fig.fullwidth), and plot dimensions, what ultimately worked for me was CSS.

Here's the top of my markdown file:

---
output:
  html_document:
    css: my_styles.css
---

and then in my_styles.css:

div.main-container {
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
}

.shiny-frame {
  height: 800px;
}

Upvotes: 1

mluerig
mluerig

Reputation: 749

shinyApp(ui, server, options = list(height = 1000)

Note the use of the height parameter to determine how much vertical space the embedded application should occupy. (http://rmarkdown.rstudio.com/authoring_embedded_shiny.html)

Upvotes: 2

Fangfei Gao
Fangfei Gao

Reputation: 1

When turn the shiny into Markdown file, I think you should delete the server and UI function because this is not a regular rmarkdown file, then it will show the whole shiny graphics. I have solved this problem by doing in this way. you can change the shiny into this formate.

Here is a link: change shiny format into rmarkdown

Upvotes: 0

Kewitschka
Kewitschka

Reputation: 1671

I achieved it by adding my own css file. You can include it like this:

---
title: "Spielercluster"
output:
  html_document:
    css: style.css
runtime: shiny
---

Then you have to adjust the sizes of the class shiny-frame

.shiny-frame{
  width: 1400px;
  height: 1200px;
}

Upvotes: 6

iboboboru
iboboboru

Reputation: 1102

To set globally

knitr::opts_chunk$set(fig.width = 12, fig.height=8)

or locally for each output

```{r,echo=FALSE, fig.width = 12, fig.height=8}

should work.

Upvotes: -1

Related Questions