我正在 RMarkdown 文档中构建一个 flexdashboard,但我遇到了交互性问题。所以我得到了一个闪亮启动和运行的解决方案,但问题是在我的工作地点,我们没有任何闪亮的服务器选项来支持我本地机器以外的任何地方的应用程序。所以我已经检查htmlwidgets
并crosstalk
希望在那里找到我需要的东西,但即使这样也适合我的问题。
具体来说,发生的事情是我有一个构建列表列表的函数。让我们调用更大的列表plots
以供参考。列表中的每个列表plots
都有 3 个元素,第一个标记p
为plotly
折线图。第二个元素是一个错误度量元素,我用它来对列表进行排序,以便具有最高错误度量的图出现在列表中的第一位。第三个元素称为type
,它基本上描述了用于构建的每个绘图的模型类型。有 2 种类型,作为参考,我将它们称为type1
和type2
。
现在 flexdashboard 的布局如下:
---
title: "Dashboard"
author: "Me"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
---
```{r global, include=FALSE}
library(ggplot2)
library(plotly)
library(htmltools)
require(htmlwidgets)
require(manipulateWidget)
theme_set(theme_classic())
source("~/directory_where_bigRun_is_stored")
# Build Plots
plots = bigRun(parameters)
# Pull out types for reference
type_vector = unlist(lapply(plots,"[", 3))
```
Column {.sidebar data-width=200}
-------------------------------------
### Filters
<form>
<input type="checkbox" name="type1" value=1>
<label for="type1"> Include type1 models</label><br>
<input type="checkbox" name="type2" value=2>
<label for="type2"> Include type2 models</label><br><br>
<input type="submit" value="Go">
</form>
```{r echo = FALSE}
tags$submit("No idea what to do here")
```
```{r eval = FALSE}
# I also tried using this package to build out checkboxes
# but that didn't work either
manipulateWidget(
{
if(length(type) == 0){
plots2 = vector(mode = 'list', length = 50)
}else{
plots2 = lapply(plots, function(x) x[x$type %in% type])
}
},
type= mwCheckboxGroup(c("type1" = 1, "type2" = 2), c(1,2)),
.updateBtn = TRUE
)
```
Row
-----------------------------------------------------------------------
### #1 Worst
```{r}
plots2[[1]][[1]]
```
### #2 Worst
```{r}
plots2[[2]][[1]]
```
如您所见,我在侧边栏中尝试了几件事来获得一个复选框,该复选框将完全符合我的要求。原始 html 代码实际上创建了一个可用的复选框,但我不知道如何与它交互以执行我需要在列表中执行的过滤。基本上,我希望复选框将列表过滤plots
成一个较小的列表,该列表plots2
仅包含复选框中选择的元素(type1
或type2
)。似乎没有任何htmlWidgets
方法适用于这个给定的场景,因为我没有更改绘图本身,而是更改了将自动打印到仪表板的绘图列表。
提前感谢您提供的任何帮助。这已经让我发疯了一个多星期了,我真的很想为仪表板解决这个障碍,因为我还需要对其进行其他更改。
作为参考,我也看过这些发布的问题,但我仍然很难过: