另一种方法是使用来自闪亮的绝对面板。与其尝试找到适合屏幕上所有部分的网格排列,不如使用带有折叠按钮的绝对面板来选择性地选择在给定时间出现的框。这允许用户选择他们想要呈现的图和信息。这个想法是从 superzip 应用程序https://shiny.rstudio.com/gallery/superzip-example.html演变而来的,但在 flexdashboard 中运行良好。
在下面的示例中,可以在页面加载时显示或隐藏绘图。单击按钮使它们出现或消失。这在将传单与地块混合时非常有用,以避免用地块淹没地图(与以前一样,由于溺水问题,地块受到限制)。
---
title: "Demo"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
library(rmarkdown)
library(plotly)
library(shiny)
```
Column {data-width=400}
--------------------------------
### Planet Earth
```{r}
library(leaflet)
m = leaflet() %>% addTiles()
m # a map with the default OSM tile layer
```
```{r}
#plot setup
mtcars$am[which(mtcars$am == 0)] <- 'Automatic'
mtcars$am[which(mtcars$am == 1)] <- 'Manual'
mtcars$am <- as.factor(mtcars$am)
p <- plot_ly(mtcars, x = ~wt, y = ~hp, z = ~qsec, color = ~am, colors = c('#BF382A', '#0C4B8E')) %>%
add_markers() %>%
layout(scene = list(xaxis = list(title = 'Weight'),
yaxis = list(title = 'Gross horsepower'),
zaxis = list(title = '1/4 mile time')))
set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]
##########################
absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
draggable = TRUE, top = 70, left = "auto", right = 20, bottom = "auto",
width = '30%', height = 'auto',
style = "overflow-y:scroll; max-height: 1000px; opacity: 0.9; style = z-index: 400",
h4(strong("Plot Explorer")),
HTML('<button data-toggle="collapse" data-target="#box1" class="btn-block btn-primary">dot plot</button>'),
tags$div(id = 'box1', class="collapse in",
plot_ly(d, x = ~carat, y = ~price, color = ~carat,
size = ~carat, text = ~paste("Clarity: ", clarity)) %>% layout(height=200)
),
HTML('<button data-toggle="collapse" data-target="#box2" class="btn-block btn-warning">histogram</button>'),
tags$div(id = 'box2', class="collapse",
plot_ly(x = rnorm(500), type = "histogram", name = "Histogram") %>% layout(height=200)
),
HTML('<button data-toggle="collapse" data-target="#box3" class="btn-block btn-danger">spinny thing</button>'),
tags$div(id = 'box3', class="collapse in",
p %>% layout(height=200)
)
)
```