制作 highcharter treemap 时,在 Shiny 中验证无法按预期工作

Validate in Shiny doesn't work as expected when making a highcharter treemap

尝试在 Shiny 中制作 highcharter treemap 时遇到了这个奇怪的事情。当不满足验证高图的条件时,我会得到这个交互式文本树图和我的验证消息(而不仅仅是文本)。

我是不是做错了什么,或者这只是 Highchart 中的一个错误?

## app.R ##
require(shiny)
require(treemap)
require(highcharter)
ui <- fluidPage(numericInput(inputId = "n",
                             "Input number", value = 1),
                highchartOutput("tree"))

server <- function(input, output, session) {
  data(GNI2014)
  tm <-  treemap(
    GNI2014,
    index = c("continent", "iso3"),
    vSize = "population",
    vColor = "GNI",
    type = "value"
  )
  output$tree <- renderHighchart({
    validate(need(input$n == 1, "Please input number 1"))
    hctreemap(tm = tm)
  })
}

shinyApp(ui, server)

这是一个解决方法,使用 renderUI

## app.R ##
require(shiny)
require(treemap)
require(highcharter)
ui <- fluidPage(numericInput(inputId = "n","Input number", value = 1),
                htmlOutput("tree"))

server <- function(input, output, session) {
  data(GNI2014)
  tm <-  treemap(
    GNI2014,
    index = c("continent", "iso3"),
    vSize = "population",
    vColor = "GNI",
    type = "value"
  )


  output$tree <- renderUI({
    validate(need(input$n == 1, "Please input number 1"))
    if(input$n != 1){
      h1 <- highchart()
    }
    else{
      h1 <- hctreemap(tm = tm)
    }
    hw_grid(h1,rowheight = 390)
  })

}

shinyApp(ui, server)