将动态图片url链接传递到shinydashboardPlus()中的UI不起作用

将动态图片url链接传递到shinydashboardPlus()中的UI不起作用,r,shiny,shinydashboard,shiny-server,shinyapps,R,Shiny,Shinydashboard,Shiny Server,Shinyapps,我正在使用shinydashboardPlus()中的widgetUserBox(),并尝试有条件地将url字符串从服务器传递到UI中widgetUserBox()的backgroundUrl选项,该选项将图像显示为用户框的背景。这不起作用,该框默认为黑色背景,而不是跟随url链接到图像 我能够成功地将文本从服务器传递到widgetUserBox的其他元素,即标题、副标题和页脚,但我无法获取backgroundUrl以跟踪链接。我曾尝试使用renderText()、renderUI()和逐字输出

我正在使用
shinydashboardPlus()
中的
widgetUserBox()
,并尝试有条件地将url字符串从服务器传递到UI中
widgetUserBox()
backgroundUrl
选项,该选项将图像显示为用户框的背景。这不起作用,该框默认为黑色背景,而不是跟随url链接到图像

我能够成功地将文本从服务器传递到widgetUserBox的其他元素,即标题、副标题和页脚,但我无法获取
backgroundUrl
以跟踪链接。我曾尝试使用
renderText()
renderUI()
逐字输出()
将url字符串传递给backgroundUrl,但都没有成功。是否有能够将url字符串从服务器发送到backgroundUrl的解决方案/解决方法

我有一个问题的例子如下:

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)

ui = dashboardPagePlus(

  header = dashboardHeaderPlus(),
  
  sidebar = dashboardSidebar(
    sidebarMenu(
      menuItem("Tab 1", tabName = "Tab_1"))) , 
    
    body = dashboardBody(
      tabItems(
        tabItem(tabName = "Tab_1" ,
            fluidRow(
                 column(4,
                       textOutput("countText") , 
                         
                       br() , 
                       br() , 
                       
                       actionButton('push','Push Me'),
                       
                       br() , 
                       br() , 
                       
                       widgetUserBox( 
                           title =  textOutput("titleText") , 
                           subtitle = textOutput("subtitleText") ,
                           type = 2,
                           width = 12,
                           background = T,
                           backgroundUrl = textOutput("urlText") ,
                           closable = F,
                           collapsible = F , 
                           textOutput("footerText"))
                       ))
                       ))
                       ))
    

server = function(input, output,session) {
 
  counter <- reactiveValues(value = 1)
  
  output$titleText <- renderText({ "Can pass text to title" })
  output$subtitleText <- renderText({ "and to subtitle" })
  output$footerText <- renderText({ "and to footer" })
  output$countText <- renderText({ paste0(counter$value) })

  
  observeEvent(input$push, {
    
    # Add to count
    counter$value <- counter$value + 1
    
    # Arbitrary condition to evaluate which text to output (if counter value is odd, display 1st image, if even then the second)
    if ((counter$value %% 2) == 0) {
      
      output$urlText <- renderText({ paste0("https://i.ibb.co/7CVQ1Vk/Carlton-Blues-Banner4.png") })
      
    } else {
      
      output$urlText <- renderText({ paste0("https://i.ibb.co/3C8dc71/Brisbane-Lions-Banner.png") })
      
      
    }
  
  })

   
}
    
shinyApp(ui = ui, server = server)

库(闪亮)
图书馆(shinydashboard)
图书馆(shinydashboardPlus)
ui=仪表板PagePlus(
header=仪表板HeaderPlus(),
侧栏=仪表板侧栏(
侧边栏菜单(
菜单项(“表1”,tabName=“表1”),
车身=仪表板车身(
tabItems(
tabItem(tabName=“Tab_1”,
fluidRow(
第(4)栏,
文本输出(“countText”),
br(),
br(),
actionButton(‘推’、‘推我’),
br(),
br(),
widgetUserBox(
标题=文本输出(“标题文本”),
字幕=文本输出(“字幕文本”),
类型=2,
宽度=12,
背景=T,
backgroundUrl=textOutput(“urlText”),
closable=F,
可折叠=F,
文本输出(“页脚文本”))
))
))
))
服务器=功能(输入、输出、会话){

counter这是一个在服务器端呈现
widgetUserBox
的解决方案

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)

ui = dashboardPagePlus(
  
  header = dashboardHeaderPlus(),
  
  sidebar = dashboardSidebar(
    sidebarMenu(
      menuItem("Tab 1", tabName = "Tab_1"))) , 
  
  body = dashboardBody(
    tabItems(
      tabItem(tabName = "Tab_1" ,
              fluidRow(
                column(4,
                       textOutput("countText") , 
                       
                       br() , 
                       br() , 
                       
                       actionButton('push','Push Me'),
                       
                       br() , 
                       br() , 
                       uiOutput("my_box")
                ))
      ))
  ))


server = function(input, output,session) {
  
  counter <- reactiveValues(value = 1)
  my_url <- reactiveVal()

  output$countText <- renderText({ paste0(counter$value) })
  
  output$my_box <- renderUI({
    widgetUserBox( 
      title =   "Can pass text to title" , 
      subtitle = "and to subtitle" ,
      type = 2,
      width = 12,
      background = T,
      backgroundUrl = my_url() ,
      closable = F,
      collapsible = F , 
      "and to footer")
  })
  
  
  observeEvent(input$push, {
    
    # Add to count
    counter$value <- counter$value + 1
    
    # Arbitrary condition to evaluate which text to output (if counter value is odd, display 1st image, if even then the second)
    if ((counter$value %% 2) == 0) {
      
      my_url("https://i.ibb.co/7CVQ1Vk/Carlton-Blues-Banner4.png")
      
    } else {
      
      my_url("https://i.ibb.co/3C8dc71/Brisbane-Lions-Banner.png")
      
      
    }
    
  })
  
  
}

shinyApp(ui = ui, server = server)

这随后用于生成
div
标记。但是,
textOutput
将文本包装在
span
div
标记中(请参见
container
参数),因此它不再是纯文本。

下面是一个在服务器端呈现
widgetUserBox
的解决方案

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)

ui = dashboardPagePlus(
  
  header = dashboardHeaderPlus(),
  
  sidebar = dashboardSidebar(
    sidebarMenu(
      menuItem("Tab 1", tabName = "Tab_1"))) , 
  
  body = dashboardBody(
    tabItems(
      tabItem(tabName = "Tab_1" ,
              fluidRow(
                column(4,
                       textOutput("countText") , 
                       
                       br() , 
                       br() , 
                       
                       actionButton('push','Push Me'),
                       
                       br() , 
                       br() , 
                       uiOutput("my_box")
                ))
      ))
  ))


server = function(input, output,session) {
  
  counter <- reactiveValues(value = 1)
  my_url <- reactiveVal()

  output$countText <- renderText({ paste0(counter$value) })
  
  output$my_box <- renderUI({
    widgetUserBox( 
      title =   "Can pass text to title" , 
      subtitle = "and to subtitle" ,
      type = 2,
      width = 12,
      background = T,
      backgroundUrl = my_url() ,
      closable = F,
      collapsible = F , 
      "and to footer")
  })
  
  
  observeEvent(input$push, {
    
    # Add to count
    counter$value <- counter$value + 1
    
    # Arbitrary condition to evaluate which text to output (if counter value is odd, display 1st image, if even then the second)
    if ((counter$value %% 2) == 0) {
      
      my_url("https://i.ibb.co/7CVQ1Vk/Carlton-Blues-Banner4.png")
      
    } else {
      
      my_url("https://i.ibb.co/3C8dc71/Brisbane-Lions-Banner.png")
      
      
    }
    
  })
  
  
}

shinyApp(ui = ui, server = server)

这随后用于生成
div
标记。但是,
textOutput
将文本包装在
span
div
标记中(请参见
容器
参数)这个解决方案对我的用例来说是很好的,保持用户的服务器端,避免使用文本输出,因为你已经解决了这个问题。谢谢你的帮助。很高兴我能帮助。如果答案是有用的,请考虑接受ITNO。这个解决方案对我的用例非常有用,保持用户箱服务。R侧,避免使用文本输出,因为您已经解决了这个问题。谢谢您的帮助。很高兴我能帮助。如果答案是有用的,请考虑接受它。