简体   繁体   English

在 R shiny 中,如何将 selectInput 作为 div 的标题(h1 标签)

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

I have a selectInput in my shiny app, and I want every input to this selectInput to change the h1 title of my fluidRow div.我的 shiny 应用程序中有一个selectInput ,我希望此selectInput的每个输入都更改我的fluidRow div 的 h1 标题。 I am trying to use glue package but it's not working.我正在尝试使用胶水 package 但它不起作用。

This is my app:这是我的应用程序:

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)

What is the best practice to change html elements when shiny inputs are changed?当 shiny 输入更改时更改 html 元素的最佳做法是什么?

You could change to htmlOutput in the UI, and then on the server side use renderUI.您可以在 UI 中更改为htmlOutput ,然后在服务器端使用 renderUI。

UI:用户界面:

htmlOutput("title")

Server:服务器:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM