r - 在 R 中缩放 Flexdashboard 仪表

标签 r shiny scaling gauge flexdashboard

我正在尝试使用 flexdashboard::gauge,但它的大小始终相同(无法缩放),而且我不知道如何更改它的大小。我知道有一种方法可以使用 renderPlot 并设置例如 height 对于普通绘图执行此操作。有没有办法用 renderGauge 做类似的事情?

这是我的代码:

---
title: "Test"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
runtime: shiny    
---



```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(googleVis)
```


Column {.sidebar}
-----------------------------------------------------------------------

```{r}
selectInput("n", label = "Number of bins:",
            choices = c(10, 20, 35, 50), selected = 20)
```



Column {data-width=500}
-----------------------------------------------------------------------


### Gauge

```{r}
renderGauge({
    invalidateLater(1000, session)
    dane <- round(runif(1,0,100))
    df <- data.frame(Label = "IRR", Value = as.numeric(dane))
    gauge(dane, min = 0, max = 100, symbol = '%', gaugeSectors(
  success = c(80, 100), warning = c(40, 79), danger = c(0, 39)
))
  })

```

### Chart A

```{r }
renderPlot({
  plot(1:10,1:10)
})
```


Column {data-width=500}
-----------------------------------------------------------------------

### Chart B

```{r}
renderPlot({
  plot(1:10,1:10)
})
```

### Chart C

```{r}
renderPlot({
  plot(1:10,1:10)
})
```

其余图表将填补该位置。 你知道如何让这个仪表变大吗? 谢谢!

最佳答案

这可能并不是太难。真正的问题似乎在于 justgage.css,它将高度固定为 160px。您可以通过添加自定义 css 来覆盖它,例如通过以下方式:

文件extra.css:

.html-widget.gauge {
  height: 100%; /*or try sth like 320px instead of 100%, whatever you prefer*/
}

.html-widget.gauge svg {
  height: 100%; /*or try sth like 320px instead of 100%, whatever you prefer*/
  margin-top: -10px;
  margin-bottom: -40px;
}

然后编辑文档的yaml header,如下所示:

---
title: "Test"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    css: extra.css
runtime: shiny
---

这需要文件 extra.css 与主文档位于同一目录中。

关于r - 在 R 中缩放 Flexdashboard 仪表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45876572/

相关文章:

R 栅格乘法 - 为什么栅格大小大幅增加

r - 如何设置表格格式以包含条形周围的轮廓

html - R : CSS defined in header is not working inside leafletProxy 的传单

three.js - 在three.js中缩放对象

kubernetes - 在 kubernetes 中,什么时候在同一节点中复制 pod 才有意义?

r - 将工具提示格式化为货币并打开比较模式

R:处理 data.frame 中的连接和平均值的最佳函数是什么?

shiny - R Shiny 应用程序显示旧数据

ruby-on-rails - 建立多人游戏网站

r - 使用 dplyr mutate 将列名传递给函数,而不使用折旧的 mutate_