gpt4 book ai didi

动态渲染 R Shiny 框中的标题

转载 作者:行者123 更新时间:2023-12-03 23:29:50 25 4
gpt4 key购买 nike

我正在尝试动态渲染我在 R 中使用的盒子的标题。

截至目前,框代码如下所示

 box( title = "lorem ipsum",
width = 6,
solidHeader = TRUE,
status = "primary",
tableOutput("consumption"),
collapsible = T
)

是否可以在服务器中使用渲染文本并将文本作为标题传递:
 con1 <- renderText({
if (age() == FALSE)
{
return("lorem1")

}
else
{
return("lorem2")
}
})

最佳答案

您应该存储 renderText 的输出如 output$x哪里x是任意的,因此您可以将该元素称为 textOutput('x')在您的盒子的标题参数中。所以一个工作示例如下所示。希望这可以帮助!

enter image description here

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
checkboxInput('mybox',label = 'Title'),
box(title=textOutput('title'),
width = 6,
solidHeader = TRUE,
status = "primary",
p('Use the checkbox to change the title of this box.')
)
)
)

server <- function(input, output) {
output$title <- renderText({ifelse(!input$mybox,'Title 1','Title 2')})
}

shinyApp(ui,server)

关于动态渲染 R Shiny 框中的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50808905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com