0

Because of this issue want to put 6 highcharter graphs in one row like do they over here. It seems to work fine outside of flexdashboard

data(diamonds, package = "ggplot2")
diamonds <- diamonds[-6]

map(names(diamonds), function(x){
  diamonds[[x]] %>% 
    hchart(showInLegend = FALSE) %>% 
    hc_add_theme(hc_theme_smpl()) %>% 
    hc_title(text = x) %>% 
    hc_yAxis(title = list(text = ""))
  }) %>% 
  hw_grid(rowheight = 225, ncol = 3)  %>% browsable()

please find a simple example here how it's not working within flexdashboard :

---
title: "test"
runtime: shiny
output:
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
---
```{r}
library(highcharter)
library(data.table)
library(ggplot2)
library(htmltools)
```


### trying to render with hw_grid

```{r}
sliderInput('ncol','ncol',min = 1,max=4,value = 2)
```


```{r}
renderHighchart({
  x <- hchart(data.table(a=c(1:5),b=c(1:5)), type='column', hcaes(x=a,y=b))
lst <- list(
  x,
  x,
  x,
  x
)

hw_grid(lst, rowheight = 300,ncol = input$ncol)  %>% browsable()
})
```

### hw_grid example without rendering

```{r}

x <- hchart(data.table(a=c(1:5),b=c(1:5)), type='column', hcaes(x=a,y=b))
lst <- list(
  x,
  x,
  x,
  x
)
ncol <- 4
# ncol <- input$ncol # need to have a render as this will triger the error: Operation not allowed without an active reactive context....
hw_grid(lst, rowheight = 300,ncol = ncol)  %>% browsable()
```

### rendering example

```{r}
renderHighchart({
  x <- hchart(data.table(a=c(input$ncol*1:5),b=c(.5 * input$ncol * 1:5)), type='column', hcaes(x=a,y=b))

})
```
Tim_Utrecht
  • 1,459
  • 6
  • 24
  • 44

1 Answers1

5

Try using renderUI and htmlOutput together like so:

---
title: "test"
runtime: shiny
output:
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
---
```{r}
library(highcharter)
library(data.table)
library(ggplot2)
library(htmltools)
library(purrr)
library(shiny)
```


### trying to render with hw_grid

```{r}
sliderInput('ncol','ncol',min = 1,max=4,value = 2)
```


```{r}
output$chart1 <- renderUI({
  x <- hchart(data.table(a=c(1:5),b=c(1:5)), type='column', hcaes(x=a,y=b))
  lst <- list(x,x,x,x)
  hw_grid(lst, rowheight = 300,ncol = input$ncol)
})

htmlOutput('chart1')
```

### hw_grid example without rendering

```{r}

x <- hchart(data.table(a=c(1:5),b=c(1:5)), type='column', hcaes(x=a,y=b))
lst <- list(
  x,
  x,
  x,
  x
)
ncol <- 4
# ncol <- input$ncol # need to have a render as this will triger the error: Operation not allowed without an active reactive context....
hw_grid(lst, rowheight = 300,ncol = ncol)  %>% browsable()
```

### rendering example

```{r}
renderHighchart({
  x <- hchart(data.table(a=c(input$ncol*1:5),b=c(.5 * input$ncol * 1:5)), type='column', hcaes(x=a,y=b))

})
```

enter image description here

Pork Chop
  • 28,528
  • 5
  • 63
  • 77
  • How can adjust the row height of the subplots? Changing `rowheight` of `hw_grid` has no effect in this example. Outside of a `Shiny` `flexdashboard` it works fine. – Ben Herbertson Sep 22 '21 at 02:57
  • @BenHerbertson have the same question, did you find out? – Mihail Mar 22 '22 at 17:16