我正在尝试动态呈现我在 R 中使用的盒子的标题。
截至目前,框代码如下所示
box( title = "lorem ipsum",
width = 6,
solidHeader = TRUE,
status = "primary",
tableOutput("consumption"),
collapsible = T
)
Run Code Online (Sandbox Code Playgroud)
是否可以在服务器中使用渲染文本并将文本作为标题传递:
con1 <- renderText({
if (age() == FALSE)
{
return("lorem1")
}
else
{
return("lorem2")
}
})
Run Code Online (Sandbox Code Playgroud)
Flo*_*ian 10
您应该将renderTextas output$xwhere的输出存储x为任意值,以便您可以textOutput('x')在框的 title 参数中引用该元素。所以一个工作示例如下所示。希望这可以帮助!
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)
Run Code Online (Sandbox Code Playgroud)