【问题标题】:Print string and reactive object in the same line in shiny app在闪亮的应用程序的同一行中打印字符串和反应对象
【发布时间】:2021-11-19 14:26:45
【问题描述】:

我尝试使用 print()paste() 在同一行中打印文本和反应对象,但它不起作用。

# define some credentials
credentials <- data.frame(
  user = c("shiny", "shinymanager"), # mandatory
  password = c("azerty", "12345"), # mandatory
  start = Sys.Date(), # optinal (all others)
  expire = c(NA, "2019-12-31"),
  admin = c(FALSE, TRUE),
  comment = "Simple and secure authentification mechanism 
  for single ‘Shiny’ applications.",
  stringsAsFactors = FALSE
)

library(shiny)
library(shinymanager)

ui <- fluidPage(
  tags$h2("My secure application"),
  uiOutput("auth_output")
)

# Wrap your UI with secure_app
ui <- secure_app(ui)


server <- function(input, output, session) {
  
  # call the server part
  # check_credentials returns a function to authenticate users
  res_auth <- secure_server(
    check_credentials = check_credentials(credentials)
  )
  
  output$auth_output <- renderText({
    print(paste0(h4("Name:"),h4(res_auth$user)))
          
  })
  
  # your classic server logic
  
}

shinyApp(ui, server)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    我突然想到的是renderText 通常与verbatimTextOutput 配对。如果你想使用uiOutput,你应该在服务器代码中将它与renderUI配对。

    话虽如此,如果您希望它在 UI 中显示一个 h4 标题,您将不会得到您所期望的。 h4 返回一个 shiny.tag 对象。 paste0 会将这些强制转换为字符。您更有可能想要创建文本,然后使用它来创建 h4。

    output$auth_output <- renderUI({
        h4(paste0("Name:", res_auth$user))
    })
    

    【讨论】:

      猜你喜欢
      • 2021-01-04
      • 2013-07-08
      • 2017-07-27
      • 2017-07-10
      • 2018-12-29
      • 2017-03-10
      • 2021-07-20
      • 2021-05-25
      • 2016-04-09
      相关资源
      最近更新 更多