Select 反应热图列
Select columns for reactive heatmap
我正在构建一个闪亮的应用程序,并希望反应性地控制在热图中显示哪些列。我希望首先显示所有列,然后能够通过从 checkboxGroupInput
.
中取消选择列来对其进行子集化
当我 运行 代码时,热图没有出现。我尝试通过查看 df_select
数据框来进行故障排除,但它只有 "mpg" 列,而最初它应该包含所有列 (mpg:carb)。包含 View(df_select)
会引发错误,因此在下面注释掉。
如有任何帮助,我们将不胜感激。
app.R
library(ggplot2)
library(d3heatmap)
library(dplyr)
library(shiny)
## ui.R
ui <- fluidPage(
sidebarPanel(
h5(strong("Dendrogram:")),
checkboxInput("cluster_row", "Cluster Rows", value=FALSE),
checkboxInput("cluster_col", "Cluster Columns", value=FALSE),
checkboxGroupInput("col_list", "Select col to include:", names(mtcars), selected=names(mtcars)),
h5(strong("Sort:")),
checkboxInput("check_sort", "Sort (Yes/No)", value=FALSE),
selectInput("sort", "Sort:", names(mtcars), selected="mpg")
),
mainPanel(
h4("Heatmap"),
d3heatmapOutput("heatmap", width = "100%", height="600px")
)
)
## server.R
server <- function(input, output) {
df_select <- reactive({
all <- names(mtcars)
print(all) #debug
selection <- input$col_list
print(selection) #debug
if("All" %in% input$col_list || length(input$col_list) == 0){
selection <- all
}else{
selection <- input$col_list
}
df_select <- select_(mtcars, selection)
#View(df_select) #debug
})
df_sort <- reactive({
df_sort <- if(input$check_sort==FALSE) df_select() else arrange_(df_select(), input$sort)
})
output$heatmap <- renderD3heatmap({
d3heatmap(df_sort(),
colors = "Blues",
if (input$cluster_row) RowV = TRUE else FALSE,
if (input$cluster_col) ColV = TRUE else FALSE,
yaxis_font_size = "7px"
)
})
}
shinyApp(ui = ui, server = server)
这是一个标准的评估问题。使用 select_(mtcars, .dots=selection)
(行号 38)。
我正在构建一个闪亮的应用程序,并希望反应性地控制在热图中显示哪些列。我希望首先显示所有列,然后能够通过从 checkboxGroupInput
.
当我 运行 代码时,热图没有出现。我尝试通过查看 df_select
数据框来进行故障排除,但它只有 "mpg" 列,而最初它应该包含所有列 (mpg:carb)。包含 View(df_select)
会引发错误,因此在下面注释掉。
如有任何帮助,我们将不胜感激。
app.R
library(ggplot2)
library(d3heatmap)
library(dplyr)
library(shiny)
## ui.R
ui <- fluidPage(
sidebarPanel(
h5(strong("Dendrogram:")),
checkboxInput("cluster_row", "Cluster Rows", value=FALSE),
checkboxInput("cluster_col", "Cluster Columns", value=FALSE),
checkboxGroupInput("col_list", "Select col to include:", names(mtcars), selected=names(mtcars)),
h5(strong("Sort:")),
checkboxInput("check_sort", "Sort (Yes/No)", value=FALSE),
selectInput("sort", "Sort:", names(mtcars), selected="mpg")
),
mainPanel(
h4("Heatmap"),
d3heatmapOutput("heatmap", width = "100%", height="600px")
)
)
## server.R
server <- function(input, output) {
df_select <- reactive({
all <- names(mtcars)
print(all) #debug
selection <- input$col_list
print(selection) #debug
if("All" %in% input$col_list || length(input$col_list) == 0){
selection <- all
}else{
selection <- input$col_list
}
df_select <- select_(mtcars, selection)
#View(df_select) #debug
})
df_sort <- reactive({
df_sort <- if(input$check_sort==FALSE) df_select() else arrange_(df_select(), input$sort)
})
output$heatmap <- renderD3heatmap({
d3heatmap(df_sort(),
colors = "Blues",
if (input$cluster_row) RowV = TRUE else FALSE,
if (input$cluster_col) ColV = TRUE else FALSE,
yaxis_font_size = "7px"
)
})
}
shinyApp(ui = ui, server = server)
这是一个标准的评估问题。使用 select_(mtcars, .dots=selection)
(行号 38)。