在R中,如何在UI端使用在服务器端计算的值?
在我的R Shining应用程序中,我想根据数据框的行数调整我的在R中,如何在UI端使用在服务器端计算的值?,r,shiny,R,Shiny,在我的R Shining应用程序中,我想根据数据框的行数调整我的d3heatmap(请参阅软件包)的高度;d3heatmapOutput中有一个参数height指定该参数 但是,我的数据帧是在服务器端计算的,因此如何将其行数从服务器端传递到ui端 下面是一个反映我想做什么的示例: runApp(shinyApp( ui = fluidRow( selectInput("am", "Automatic (0) or manual (1) transmission?",
d3heatmap
(请参阅软件包)的高度;d3heatmapOutput
中有一个参数height
指定该参数
但是,我的数据帧是在服务器端计算的,因此如何将其行数从服务器端传递到ui端
下面是一个反映我想做什么的示例:
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")
})
}
))
runApp(shinyApp)(
ui=fluidRow(
选择输入(“am”、“自动(0)或手动(1)变速器?”,
选择=c(0,1)),
#如何使'height'参数等于'output$height'?
#我不能使用“textOutput(“height”),因为它给出的是html代码,而不是值。
D3Heatmap输出(“heatmap”,height=“400px”)
),
服务器=功能(输入、输出){
mtcars2=无功({
mtcars[其中(mtcars$am==输入$am),]
})
输出$height您可以使用ui.R
中的uiOutput
和server.R
中的renderUI
动态添加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")
})
}
))
库(闪亮)
图书馆(热图)
runApp(shinyApp)(
ui=fluidRow(
选择输入(“am”、“自动(0)或手动(1)变速器?”,
选择=c(0,1)),
uiOutput(“ui\U热图”)
),
服务器=功能(输入、输出){
mtcars2=无功({
mtcars[其中(mtcars$am==输入$am),]
})
输出$ui\u热图