【问题标题】:Add conditional text outpuT to cardprofile将条件文本输出添加到 cardprofile
【发布时间】:2021-09-01 05:53:27
【问题描述】:

我正在使用来自bs4Dash 库的cardProfile 在我的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 ]
})

【问题讨论】:

    标签: r shiny shinydashboard bs4dash


    【解决方案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
              
            )
          )
        })
        }
    )
    

    【讨论】:

      猜你喜欢
      • 2017-03-28
      • 2014-01-12
      • 1970-01-01
      • 2013-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多