在我的 R闪亮应用程序中,我想调整我的高度d3heatmap
(见包装d3热图 https://cran.r-project.org/web/packages/d3heatmap/index.html)作为我的数据框行数的函数;有一个论点height
in the d3heatmapOutput
来指定这一点。
但是,我的数据框是在服务器端计算的,那么如何将其行数从服务器端传递到用户界面端呢?
这是反映我想做的事情的示例:
runApp(shinyApp(
ui = fluidRow(
selectInput("am", "Automatic (0) or manual (1) transmission?",
choices = c(0,1)),
# How can I have the 'height' argument equal to 'output$height'?
# I cannot use 'textOutput("height")' since it gives html code, not a value.
d3heatmapOutput("heatmap", height = "400px")
),
server = function(input, output) {
mtcars2 = reactive({
mtcars[which(mtcars$am == input$am),]
})
output$height <- renderText({
paste0(15*nrow(mtcars2()), "px")
})
output$heatmap <- renderD3heatmap({
d3heatmap(mtcars2(), scale = "column")
})
}
))
谢谢。
您可以使用uiOutput
in ui.R
and renderUI
in server.R
动态添加d3heatmapOutput
:
library(shiny)
library(d3heatmap)
runApp(shinyApp(
ui = fluidRow(
selectInput("am", "Automatic (0) or manual (1) transmission?",
choices = c(0,1)),
uiOutput("ui_heatmap")
),
server = function(input, output) {
mtcars2 = reactive({
mtcars[which(mtcars$am == input$am),]
})
output$ui_heatmap <- renderUI({
d3heatmapOutput("heatmap", height = paste0(15*nrow(mtcars2()), "px"))
})
output$heatmap <- renderD3heatmap({
d3heatmap(mtcars2(), scale = "column")
})
}
))
然后,您可以在应用程序的服务器端设置热图的高度。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)