我正在使用R的d3heatmap库:https://cran.r-project.org/web/packages/d3heatmap/d3heatmap.pdf构建一个热图
我希望能够允许用户(通过UI)自由地调整d3heatmapOutput()函数中的d3heatmapOutput()参数。
比较以下两个代码片段(只需将它们直接复制/粘贴到R中),其中唯一的区别是height =参数在d3heatmapOutput()中的值
library(d3heatmap)
library(shiny)
ui <- fluidPage(
h1("A heatmap demo"),
selectInput("palette", "Palette", c("YlOrRd", "RdYlBu", "Greens", "Blues")),
checkboxInput("cluster", "Apply clustering"),
d3heatmapOutput("heatmap", height = "400px")
)
server <- function(input, output, session) {
output$heatmap <- renderD3heatmap({
d3heatmap(
scale(mtcars),
colors = input$palette,
dendrogram = if (input$cluster) "both" else "none"
) })
}
shinyApp(ui, server)VS.
library(d3heatmap)
library(shiny)
ui <- fluidPage(
h1("A heatmap demo"),
selectInput("palette", "Palette", c("YlOrRd", "RdYlBu", "Greens", "Blues")),
checkboxInput("cluster", "Apply clustering"),
d3heatmapOutput("heatmap", height = "1000px")
)
server <- function(input, output, session) {
output$heatmap <- renderD3heatmap({
d3heatmap(
scale(mtcars),
colors = input$palette,
dendrogram = if (input$cluster) "both" else "none"
) })
}
shinyApp(ui, server)我想让用户自己选择height =的这个值。但是,由于"400px"是一个非数值参数,所以UI工具(如numericInput() )无法工作。同样,selectInput()也不起作用,例如:
selectInput("foo", "Bar:", c("400px", "700px", "1000px"))在哪里d3heatmapOutput("heatmap", height = "foo")。不幸的是,这两个选项都不起作用,这让我怀疑我是否忽略了一个更简单、更优雅的选项。
发布于 2016-05-18 14:41:11
在本例中,您可以使用滑块控制绘图的高度。其思想是在服务器端呈现映射,并使用paste0函数设置所需的像素大小。
library(d3heatmap)
library(shiny)
ui <- fluidPage(
h1("A heatmap demo"),
sliderInput("pixels", "size", value = 400, min = 100, max = 1000),
selectInput("palette", "Palette", c("YlOrRd", "RdYlBu", "Greens", "Blues")),
checkboxInput("cluster", "Apply clustering"),
uiOutput("dynamic")
)
server <- function(input, output, session) {
output$heatmap <- renderD3heatmap({
d3heatmap(
scale(mtcars),
colors = input$palette,
dendrogram = if (input$cluster) "both" else "none"
) })
output$dynamic <- renderUI({
d3heatmapOutput("heatmap", height = paste0(input$pixels, "px"))
})
}
shinyApp(ui, server)https://stackoverflow.com/questions/37300026
复制相似问题