How can I insert an image into the navbar on a shiny navbarPage()

后端 未结 4 549
一向
一向 2020-11-29 04:54

I am builidng a shiny application using a navbarPage() layout. I would like to insert an image to be on the right hand side of the screen, in the navigation bar

4条回答
  •  星月不相逢
    2020-11-29 05:05

    I can now answer this question, at least for shiny 0.10.0. The general idea is to set the title= to a div() that contains both the image and the text for the the title.

    This however, creates a new problem in that the icon= argument no longer works, and you cannot set a title for the window. To get around this I followed Andy Singleton's advice here.The advice is to create a fluidPage() above the navbarPage() that can be used to hold the window title and icon. By making this page 0 pixels in height, it is hidden on the app. Here is the key bits of code.

    ui.r:

    shnyUI(
      fluidPage(
         list(tags$head(HTML(''))),
         div(style="padding: 1px 0px; width: '100%'",
             titlePanel(
                    title="", windowTitle="My Window Title"
             )
          ),
          navbarPage(
             title=div(img(src="myLogo.gif"), "My Title in the Navbar"),
             tabPanel(....
    

提交回复
热议问题