我正在尝试使用Shiny使用R创建一个简单的应用程序,该应用程序只有通过滑块通过给定参数更改了一个高图。 我浏览了Web,但是没有任何清晰的教程或简单的示例可以与我的代码进行比较。 所以这是我的代码:
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)
这是我运行应用程序时遇到的错误:
警告:服务器中的错误:找不到函数“ renderChart” 52:服务器[<..> / CTI / app.R#23] 服务器错误(...):找不到函数“ renderChart”
我一直在搜索,但未发现任何相关信息。如果您能通过此简单的代码帮助我,我将不胜感激。
答案 0 :(得分:0)
您需要使用软件包renderHighchart()
中的函数highcharter
而不是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)