Highchart 不在 Shiny 中呈现,而是在交互模式下呈现

Highchart not rendering in Shiny but rendering in interactive mode

我正在尝试 运行 以下闪亮的应用程序,它由两个 selectInput 和一个 highChartOutput 组成:

library(shiny)
library(shinythemes)
library(purrr)
library(highcharter)

ui <- fluidPage(
  titlePanel(title = "Highcharter"),
  theme = shinytheme("flatly"),
  sidebarLayout(
   sidebarPanel(
      selectInput(inputId = "xvar", label = "Select variable for X axis",
                  choices = names(iris)[-5], multiple = FALSE),
      br(),
      selectInput(inputId = "yvar", label = "Select variable for Y axis",
                  choices = names(iris)[-5], multiple = FALSE)
    ),
   mainPanel(
      highchartOutput(outputId = "hc1")
    )
  )
)

server <- function(input, output) {

  dat_setosa <- eventReactive(c(input$xvar, input$yvar),{
      split(iris[iris$Species == "setosa", c(input$xvar, input$yvar), drop = 
FALSE], seq_len(nrow(iris[iris$Species == "setosa", ]))) %>% 
      map(~as.numeric(.x)) %>% 
      set_names(NULL)
  })

  dat_virginica <- eventReactive(c(input$xvar, input$yvar),{
      split(iris[iris$Species == "virginica", c(input$xvar, input$yvar), 
drop = FALSE], seq_len(nrow(iris[iris$Species == "virginica", ]))) %>% 
      map(~as.numeric(.x)) %>% 
      set_names(NULL)
  })

  dat_versicolor <- eventReactive(c(input$xvar, input$yvar),{
      split(iris[iris$Species == "versicolor", c(input$xvar, input$yvar), 
drop = FALSE], seq_len(nrow(iris[iris$Species == "versicolor", ]))) %>% 
      map(~as.numeric(.x)) %>% 
      set_names(NULL)
  })

  output$hc1 <- renderHighchart({
    highchart() %>% 
      hc_chart(type = "scatter") %>% 
      hc_series(
        list(
          name = "setosa",
          color = "#01B88A",
          data = dat_setosa
        ),
        list(
          name = "viriginica",
          color = "#374649",
          data = dat_virginica
        ),
        list(
          name = "versicolor",
          color = "#FD625E",
          data = dat_versicolor
        )
      )
  })
}

shinyApp(ui = ui, server = server)

当我 运行 这个应用程序时,highchart 没有呈现。以下是我得到的输出:

如果我 运行 通过控制台以交互方式生成类似的高图,则高图会在“查看器”选项卡中正确呈现:

library(purrr)
library(highcharter)

dat_setosa <- split(iris[iris$Species == "setosa", c("Sepal.Length", 
"Sepal.Length"), drop = FALSE], seq_len(nrow(iris[iris$Species == "setosa", 
]))) %>% 
  map(~as.numeric(.x)) %>% 
  set_names(NULL)

dat_virginica <- split(iris[iris$Species == "virginica", c("Sepal.Length", 
"Sepal.Length"), drop = FALSE], seq_len(nrow(iris[iris$Species == 
"virginica", ]))) %>% 
  map(~as.numeric(.x)) %>% 
  set_names(NULL)

dat_versicolor <- split(iris[iris$Species == "versicolor", c("Sepal.Length", 
"Sepal.Length"), drop = FALSE], seq_len(nrow(iris[iris$Species == 
"versicolor", ]))) %>% 
  map(~as.numeric(.x)) %>% 
  set_names(NULL)

highchart() %>% 
  hc_chart(type = "scatter") %>% 
  hc_series(
    list(
      name = "setosa",
      color = "#01B88A",
      data = dat_setosa
    ),
    list(
      name = "viriginica",
      color = "#374649",
      data = dat_virginica
    ),
    list(
      name = "versicolor",
      color = "#FD625E",
      data = dat_versicolor
    )
  )

这是输出:

Shiny 应用程序哪里出错了?

反应式是函数,应该在末尾用括号调用 ()

output$hc1 <- renderHighchart({
    highchart() %>% 
      hc_chart(type = "scatter") %>% 
      hc_series(
        list(
          name = "setosa",
          color = "#01B88A",
          data = dat_setosa()
        ),
        list(
          name = "viriginica",
          color = "#374649",
          data = dat_virginica()
        ),
        list(
          name = "versicolor",
          color = "#FD625E",
          data = dat_versicolor()
        )
      )
  })