在R中,我创建了一个使用标签的shiny
布局的flexdashboard
应用。
我想在其中一个标签中包含dygraph
,但图表会从容器中删除。
我尝试在dygraph
和输出中更改宽度和高度,但它们似乎都不起作用。
最低工作示例:
---
title: "Example"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r global, include=FALSE}
library(dygraphs)
data=data.frame(x=1:10,y=11:20,val=21:30)
ymin=min(data$y,na.rm=TRUE)
ymax=max(data$y,na.rm=TRUE)
```
TABS {.tabset}
-----------------------------------------------------------------------
### Tab1
```{r singleSlider }
sliderInput("sliceval", "Observation:",
min = ymin, max = ymax,step=1,
value = 11,width="90%")
```
```{r dygraph}
# Tried also changing height width to px
output$sliceGraph <- renderDygraph({
dygraph(data[input$sliceval>=data$y,c("x","val")],height="50%",width="80%")
})
# Tried also changing height width to %
dygraphOutput("sliceGraph",height='100px',width='100px')
```
### Tab 2
Some stuff here
有没有办法让dygraph
正确适合这种布局?
答案 0 :(得分:2)
我再次查看documentation for using flexdashboard并使用他们推荐的fillCol
或fillRow
进行更多控制。具体来说,尝试这种布局:
```{r singleSlider, echo=FALSE}
fillCol(height = 600, flex = c(NA, 1),
sliderInput("sliceval", "Observation:",
min = ymin, max = ymax,step=1,
value = 11,width="90%"),
# Tried also changing height width to %
dygraphOutput("sliceGraph",height='400px',width='100%')
)
# Tried also changing height width to px
output$sliceGraph <- renderDygraph({
dygraph(data[input$sliceval>=data$y,c("x","val")],height="50%",width="80%")
})
```