3

I'm trying to make a simple app with R using shiny that only has a highchart changing with the given parameter through slidebar. I've looked through web, but there aren't any clear tutorial or simple example that I can compare my code with it. So here's my code:

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)

and this is the error that I get when I run the app:

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

I've been searching but I haven't found anything related. I'd appreciate it if you help me with this simple code.

Kimia H.
  • 33
  • 1
  • 3

1 Answers1

2

You need to use function renderHighchart() from the package highcharter to render your chart instead of renderChart(). Your code should look like this:

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)
Ferand Dalatieh
  • 313
  • 1
  • 4
  • 14