我想显示多个过滤器从crosstalk在一个四分仪表板下彼此.不幸的是,它们并不都是可见的.在这里,我创建了一些可复制的代码:

---
title: "Palmer Penguins"
author: "Quinten"
format: dashboard
#logo: penguins.png
theme: zephyr
---

```{r}
# import packages
library(tidyverse)
library(crosstalk)
library(DT)
library(plotly)
library(gt)
library(palmerpenguins)

# import data
penguins <- palmerpenguins::penguins

# Crosstalk dataset
shared_penguins <- SharedData$new(penguins)

# Set theme
theme_set(theme_minimal())
```

# {.sidebar}

This is a simple static dashboard to show what is possible with the newest version of [Quarto v1.4](https://quarto.org/docs/blog/posts/2024-01-24-1.4-release/). To make it a bit interactive we use the [crosstalk](https://github.com/rstudio/crosstalk) package and [plotly](https://plotly.com/r/).

***

In this dashboard we visualize the [palmerpenguins](https://allisonhorst.github.io/palmerpenguins/) dataset. In the table below is some basic information about the data:

| Specie       |  Count             |
|--------------|---------------------|
| **Adelie**     | `{r} nrow(subset(penguins, species == "Adelie"))`  |
| **Gentoo**   | `{r} nrow(subset(penguins, species == "Gentoo"))`   |
| **Chinstrap**  | `{r} nrow(subset(penguins, species == "Chinstrap"))` |

***

# Analysis

## Row {height=40%}

### Column {width=70%}

```{r}
#| title: "Slider options"
filter_slider("bill_length_mm", "bill length", shared_penguins, ~bill_length_mm)
filter_slider("bill_depth_mm", "bill depth", shared_penguins, ~bill_depth_mm)
filter_slider("flipper_length_mm", "flipper length", shared_penguins, ~flipper_length_mm)
filter_slider("body_mass_g", "body mass", shared_penguins, ~body_mass_g)
```

### Column {width=30%}

```{r}
filter_checkbox("sex", "sex", shared_penguins, ~sex)
```


## Row {height=60%}

```{r}
#| title: "Flipper length vs body mass"
p <- ggplot(shared_penguins, aes(x = flipper_length_mm, y = body_mass_g, color = species, shape = species)) +
  geom_point() +
  scale_color_manual(values = c("darkorange","darkorchid","cyan4")) 

ggplotly(p)
```

输出:

enter image description here

正如你所看到的,滑块选项并不都是可见的.盒子里放不下.当你点击该部分的弹出窗口时,它会显示得更好:

enter image description here

有没有办法在弹出窗口中更明显地显示滑块?

推荐答案

首先,将所有滑块都设置为<div>,这样我们就可以在不影响页面其余部分的情况下更改其子对象的css.您的第一个R块可以是:

slider_width = 700
#| title: "Slider options"
htmltools::div(
    id = "sliderdiv", 
    filter_slider("bill_length_mm", "bill length", shared_penguins, ~bill_length_mm, width = slider_width),
    filter_slider("bill_depth_mm", "bill depth", shared_penguins, ~bill_depth_mm, width = slider_width),
    filter_slider("flipper_length_mm", "flipper length", shared_penguins, ~flipper_length_mm, width = slider_width),
    filter_slider("body_mass_g", "body mass", shared_penguins, ~body_mass_g, width = slider_width)
)

我已经手动设置了width,以防你想做的事情,但你可能不需要.然后在文档的开头加入一些CSS,以便:

  1. 将标签文本变小并将其向下移动一点.
  2. 使滑块值文本变小.
  3. 移除网格标签(您可以看到所 Select 的滑块值以及当您拖动它时).
<style>
#sliderdiv .control-label {
    font-size: 10px;
    position: relative;
    top: 25px;
    left: 30px;
}
#sliderdiv .irs-from, #sliderdiv .irs-to {
    font-size: 8px !important;
}
#sliderdiv .irs-grid {
    display: none !important;
}
</style>

您可能希望稍微玩弄一下这些值,但本质上这意味着可以显示的内容更少.即使我们看到框变得足够小,需要一个垂直滚动条,滑块、标签和值仍然可见:

enter image description here

R相关问答推荐

卸载安装了BRM的模型发出的警告

基于现有类创建类的打印方法(即,打印tibles更长时间)

更改编号列表的 colored颜色

如何按排序顺序打印一个框架中所有精确的唯一值?

如何写一个R函数来旋转最后n分钟?

如何在一次运行中使用count进行多列计数

如何使用STAT_SUMMARY向ggplot2中的密度图添加垂直线

有效识别长载体中的高/低命中

查找所有站点的最小值

将数据集旋转到长格式,用于遵循特定名称模式的所有变量对

如何显示准确的p值而不是<;0.001*?

我需要使用ggplot2制作堆叠条形图

抽样变换-REXP与RWEIBUR

R:使用ApexCharge更改标签在饼图中的位置

网络抓取NBA.com

了解nchar在列表上的意外行为

R dplyr::带有名称注入(LHS of:=)的函数,稍后在:=的RHS上引用

将y轴格式更改为R中的百分比

使用dplyr删除具有条件的行

向内存不足的数据帧添加唯一行