score:2

Accepted answer

Hi you can try this solution, it do not use the same function as you but one by @jenesaisquoi (found here), this function create several plots and handle the layout correctly :

# Packages
library("highcharter")
library("shiny")

# data
df <- data.frame(
  var1 = rnorm(10),
  var2 = rnorm(10),
  var3 = rnorm(10),
  var4 = rnorm(10),
  var5 = rnorm(10),
  var6 = rnorm(10),
  var7 = rnorm(10)
)

# Fun by @jenesaisquoi (modified with highchartOutput)
makePlotContainers <- function(n, ncol=2, prefix="plot", height=100, width="100%", ...) {
  ## Validate inputs
  validateCssUnit(width)
  validateCssUnit(height)

  ## Construct plotOutputs
  lst <- lapply(seq.int(n), function(i)
    highchartOutput(sprintf('%s%g', prefix, i), height=height, width=width))

  ## Make columns
  lst <- lapply(split(lst, (seq.int(n)-1)%/%ncol), function(x) column(12/ncol, x))
  do.call(tagList, lst)
}

You can use @jenesaisquoi's function directly in the ui, and use lapply in the server for define as many outputs as the number of cols :

# App
ui <- fluidPage(
  # Application title
  titlePanel("Hello World!"),

  # Show plots
  makePlotContainers(n = ncol(df), ncol = 3, prefix = "hcontainer", height = "400px")
)

server <- function(input, output) {
  lapply(
    X = seq_len(ncol(df)),
    FUN = function(i) {
      output[[paste0("hcontainer", i)]] <- renderHighchart({
        highchart() %>%
          hc_add_serie(name = paste("df name", i), data = df[[i]])
      })
    }
  )
}
shinyApp(ui = ui, server = server)

Related Query

More Query from same tag