使用 shiny 和 highcharter 开发交互式应用程序

developing interactive app using shiny and highcharter

我正在尝试使用 R 使用 shiny 制作一个简单的应用程序,它只有一个 highchart 通过滑动条随给定参数变化。 我浏览过网络,但没有任何清晰的教程或简单的示例可以将我的代码与它进行比较。 所以这是我的代码:

library(shiny)
library(highcharter)
library(dplyr)

sigene_all = read_csv("res/significant_genes.csv")

ui <- fluidPage(
  titlePanel("Interactive Heatmap"),
  sidebarLayout(
    sidebarPanel(sliderInput(inputId = "slider", label = "Number of Cancers", min = 1, max = 12, value = 9)),
    mainPanel(highchartOutput("heatmap"))
  )
)

server <- function(input, output) {
  output$heatmap <- renderChart({
    hchart(sigene_all %>% filter(count >= input$slider),
           type = "heatmap", hcaes(x = gene, y = cancer_type, value = sgnf), name = "sgnf") %>% 
      hc_add_theme(hc_theme_darkunica())
  })
}

shinyApp(ui = ui, server = server)

这是我在 运行 应用程序时遇到的错误:

Warning: Error in server: could not find function "renderChart" 52: server [<..>/CTI/app.R#23] Error in server(...) : could not find function "renderChart"

我一直在搜索,但没有找到任何相关内容。如果你能帮助我完成这个简单的代码,我将不胜感激。

您需要使用包 highcharter 中的函数 renderHighchart() 来呈现您的图表,而不是 renderChart()。您的代码应如下所示:

library(shiny)
library(highcharter)
library(dplyr)

sigene_all = read_csv("res/significant_genes.csv")

ui <- fluidPage(
  titlePanel("Interactive Heatmap"),
  sidebarLayout(
    sidebarPanel(sliderInput(inputId = "slider", label = "Number of Cancers", min = 1, max = 12, value = 9)),
    mainPanel(highchartOutput("heatmap"))
  )
)

server <- function(input, output) {
  output$heatmap <- renderHighchart({
    hchart(sigene_all %>% filter(count >= input$slider),
           type = "heatmap", hcaes(x = gene, y = cancer_type, value = sgnf), name = "sgnf") %>% 
      hc_add_theme(hc_theme_darkunica())
  })
}

shinyApp(ui = ui, server = server)