R Markdown输出大小

8
我希望生成一个包含交互式shiny应用的R markdown页面。它可以正常工作,但输出区域非常小且需要滚动条。我想要消除滚动条并展示两张完整宽度和高度的图像。怎样可以实现这个目标?
我已经尝试过:
options(width = 800)

目前它看起来是这样的:在此输入图像描述

    ---
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)
```
5个回答

6

我通过添加自己的CSS文件来实现它。您可以像这样包含它:

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

然后,您需要调整shiny-frame类的尺寸。
.shiny-frame{
  width: 1400px;
  height: 1200px;
}

2

1
我是在CentOs 7.5上使用R Shiny Server Pro 1.5.11.994。在尝试了服务器选项、图表尺寸(如fig.widthfig.fullwidth)和绘图尺寸后,最终我采用了CSS方法。以下是我的Markdown文件的顶部内容:
---
output:
  html_document:
    css: my_styles.css
---

然后在 my_styles.css 中:
div.main-container {
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
}

.shiny-frame {
  height: 800px;
}

对我来说没有任何变化。 - Ben

0

当将闪亮转换为Markdown文件时,我认为您应该删除服务器和UI功能,因为这不是常规的rmarkdown文件,然后它将显示整个闪亮图形。我通过以下方式解决了这个问题。 您可以将闪亮更改为此格式。

这里有一个链接:将闪亮格式更改为rmarkdown


你能否发布一下你用来解决问题的清理过的代码版本? - Nate

-1

设置全局

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

或者针对每个输出本地化

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

应该可以工作。


很遗憾,它并没有改变任何事情。 - Kewitschka
1
fig.width等属性对绘图渲染的大小没有任何影响。 - Janna Maas

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接