簡體   English   中英

在 R shiny 中,如何將 selectInput 作為 div 的標題(h1 標簽)

[英]in R shiny, how to make selectInput as title of div (h1 tag)

我的 shiny 應用程序中有一個selectInput ,我希望此selectInput的每個輸入都更改我的fluidRow div 的 h1 標題。 我正在嘗試使用膠水 package 但它不起作用。

這是我的應用程序:

library(shiny)

ui <- fluidPage(

  fluidRow(
    column(6,
           selectInput('names',
                       label = "Selection",
                       choices= names(mtcars))),
    column(6,
           tags$html(h1(glue::glue("title {input$names}"))))
  )
)

server <- function(input, output, session) {

}

shinyApp(ui, server)

當 shiny 輸入更改時更改 html 元素的最佳做法是什么?

您可以在 UI 中更改為htmlOutput ,然后在服務器端使用 renderUI。

用戶界面:

htmlOutput("title")

服務器:

output$title <- renderUI({
  HTML(<h1>paste0("title: ", input$names))
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM