Highchart不是以Shiny渲染,而是以交互模式渲染

时间:2019-03-21 11:43:16

标签: r shiny r-highcharter

我正在尝试运行以下包含两个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)

当我运行此应用程序时,不会显示高度图表。以下是我得到的输出: enter image description here

如果我通过控制台交互运行类似的highcharter,则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
    )
  )

这里是输出: enter image description here

我在Shiny应用程序中哪里出了问题?

1 个答案:

答案 0 :(得分:1)

反应堆是函数,应在val rddA = ... val rddB = ... val numOfPartitions = rddA.getNumPartitions val rddApartitioned = rddA.partitionBy(new HashPartitioner(numOfPartitions)) val rddBpartitioned = rddB.partitionBy(new HashPartitioner(numOfPartitions)) val rddAB = rddApartitioned.join(rddBpartitioned)

后面加上方括号来调用
()

enter image description here