0

我想在我的 Shiny 应用程序上显示一些不同的图,将它们分成小的命名部分(使用 Markdown 的###)。但是,我在这些部分中打印的图的底部被切掉了。不仅如此,当我改变它们的data-height属性时,它们会拉伸以保证它们仍然会被切割。

在此处输入图像描述

在此处输入图像描述

我也许可以设置一个足够大的数据高度值,它根本不会剪切图像,但到那时它会非常变形。如何在调整其所在部分的大小时保持绘图相同的大小?或者更好的是,是否有可能使截面大小自动适应绘图大小?

- - 编辑:

---
title: "title"
author: "author"
date: "date"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: scroll
    logo: ""
    favicon: ""
    source_code: embed
    runtime: shiny
runtime: shiny
---

```{r setup, include=FALSE}
library (tidyverse)
```

# Tab 1

## Column

### Section 1

```{r echo=FALSE}
# Data processing

inputPanel (
    # inputs
)

renderPlot ({
    # Data processing

    step = 0.05
    max = step * ceiling(max(retention_rate$high) / step)
    min = step * floor(min(retention_rate$low) / step)

    ggplot (retention_rate,
            aes (x = dsi, y = median,
                 ymin = low, ymax = high,
                 colour = ab_group, fill = ab_group)) +
        theme (panel.background = element_rect (fill = 'white'),
               panel.grid.major = element_line (colour = 'grey90', size = 0.20),
               panel.grid.minor = element_line (colour = 'grey90', size = 0.10),
               plot.title = element_text (lineheight = 1.15),
               axis.title.y = element_text (angle = 0),
               axis.title = element_text (size = 10),
               text = element_text (size = 10),
               legend.title = element_text (size = 10),
               strip.text = element_text (size = 10, angle = 0),
               plot.caption = element_text (hjust = 0.5, size = 9)) +
        geom_vline (xintercept = c (1, 3, 7, 14, 28),
                    colour = 'gray80', linetype = 2, size = 0.4) +
        geom_line () +
        geom_ribbon (aes (colour = NULL), alpha = 0.2) +
        scale_x_continuous (breaks = seq (0, max (retention_rate$dsi), 5)) +
        scale_y_continuous (limits = c  (min, max),
                            breaks = seq (min, max, step),
                            labels = sprintf ('%.0f %%', 100 * seq (min, max, step))) +
        scale_colour_brewer (palette = 'Dark2') +
        scale_fill_brewer (palette = 'Dark2') +
        facet_grid (source~country) +
        labs(x = '',
             y = '',
             colour = '',
             fill = '',
             title = '',
             subtitle = '')
})
```

### Days Active

```{r echo=FALSE}
# Data processing

inputPanel (
    # inputs
)

renderPlot ({
    # Data processing

    step = 0.5
    max = step * ceiling(max(da$high) / step)
    min = 0

    ggplot (da, aes (x = '', y = median,
                     ymin = low, ymax = high,
                     colour = ab_group, fill = ab_group)) +
        theme (panel.background = element_rect (fill = 'white'),
               panel.grid.major = element_line (colour = 'grey90', size = 0.20),
               panel.grid.minor = element_line (colour = 'grey90', size = 0.10),
               plot.title = element_text (lineheight = 1.15),
               axis.title.y = element_text (angle = 0),
               axis.title = element_text (size = 10),
               text = element_text (size = 10),
               legend.title = element_text (size = 10),
               strip.text = element_text (size = 10, angle = 0),
               plot.caption = element_text (hjust = 0.5, size = 9)) +
        geom_col (aes (colour = NULL), position = 'dodge', alpha = 0.60, width = 2 / 3) +
        geom_errorbar (position = position_dodge (width = 2 / 3), width = 1 / 3) +
        geom_text (position = position_dodge (width = 2 / 3),
                   aes (label = sprintf ('%.2f', median)), #hjust = - 1 / (nrow (da) - 1),
                   vjust = -1) +
        scale_y_continuous (limits = c (min, max),
                            breaks = seq (min, max, step)) +
        scale_colour_brewer (palette = 'Dark2') +
        scale_fill_brewer (palette = 'Dark2') +
        facet_grid (source~country) +
        labs (x = '',
              y = '',
              fill = '', colour = '',
              title = '',
              subtitle = '')
})
```
4

1 回答 1

0

我无法重现您的示例,因为我没有retention_rate,所以我使用了mtcars 数据,将renderPlot 高度设置为1000 来模拟裁剪。

我在上图中使用library (miniUI)中的 miniContentPanel和scrollable = TRUE。现在你有一个垂直滚动条,不像下面的图。

在此处输入图像描述

---
title: "title"
author: "author"
date: "date"
output: 
  flexdashboard::flex_dashboard:
  orientation: columns
vertical_layout: scroll
logo: ""
favicon: ""
source_code: embed
runtime: shiny
---

```{r, setup, include=FALSE}
library (tidyverse)
library(miniUI)

```

# Tab 1

## Column

### Section 1

```{r, echo=FALSE}
# Data processing

inputPanel (
  # inputs
)

## Upper plot with miniContentPanel and scrollable = TRUE
miniContentPanel(
  renderPlot ({
    ggplot(mtcars,aes(x=mpg,y=cyl))+
      geom_point()
  },height=1000),
  scrollable = TRUE)

```

### Days Active

```{r, echo=FALSE}
# Data processing

inputPanel (
  # inputs
)

## lower plot without miniContentPanel ----
renderPlot({
  ggplot(mtcars,aes(x=gear,y=wt))+
    geom_point()},
height=1000)

```
于 2017-01-18T13:15:40.600 回答