0

我正在使用cardProfile来自bs4Dash库来显示我的应用程序中的当前用户Shiny

cardProfile 在ui零件中看起来像这样:

   cardProfile(
     src = "logo.png",
     title = 'SHOW HERE THE USERNAME'
     subtitle = "Administrator",
     cardProfileItemList(
       bordered = TRUE,
       cardProfileItem(
         title = "Email",
         description = 'SHOW HERE THE EMAIL'
       )
     )

我应该在标题和描述中使用什么来根据输入显示名称和电子邮件?

我尝试过textOutput

title = textOutput('title')

description = textOutput('email')

并且在server没有结果的部分中发生反应:

reactive({
  USER <- input$user
  output$title<- USER 
  output$email<- usuarios$email[usuarios$usuario == USER ]
})
4

1 回答 1

1

您需要在 renderUI() 中定义您的卡片服务器端,然后使用 UIOuptut() 在 UI 中显示它。

几乎每次您需要在 UI 中显示反应性的东西时,您都必须在服务器端对其进行编码,或者在它存在时使用 updateInput 函数。

library(shiny)
library(bs4Dash)

df_email <- data.frame(user = "toto",
                       email = "toto@toto.com")

shinyApp(
  ui = dashboardPage(,
                     header = dashboardHeader(),
                     sidebar = dashboardSidebar(),
                     body = dashboardBody(
                       bs4Card(
                         uiOutput("card_user")
                       )
                     ),
                     title = "DashboardPage"
  ),
  
  server = function(input, output) { 

    # USER <- reactive(input$user) #uncomment
    USER <- reactive("toto") #comment
    
    output$card_user <- renderUI({
      cardProfile(
        # src = "logo.png",
        title = 'SHOW HERE THE USERNAME',
        subtitle = "Administrator",
        cardProfileItem(
          title = USER(),
          description = df_email$email[df_email$user == USER()] #replace with your own data
          
        )
      )
    })
    }
)
于 2021-06-16T14:41:32.237 回答