rshinyshinythemes

Insert Figure in shiny navbarPage


Friends could help me insert a figure into my shiny navbarPage. I would like to remove the written word "Simulation" in my navbarPage and insert the attached figure instead. Is this possible to do in shiny? any help is appreciated. The executable code is below.

library(shiny)
library(shinytables)

ui <- bootstrapPage(
  navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
              "Simulation", 
  sidebarLayout(
    sidebarPanel(
      sliderInput("bins",
                  "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)
    ),
    
    sidebarLayout(
      sidebarPanel(
        sliderInput("bins",
                    "Number of bins:",
                    min = 1,
                    max = 20,
                    value = 30),
      ),
      mainPanel(
        plotOutput("distPlot")
      )
    )
  )))

server <- function(input, output) {
  
  output$distPlot <- renderPlot({
    # generate bins based on input$bins from ui.R
    x    <- faithful[, 2]
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    
    # draw the histogram with the specified number of bins
    hist(x, breaks = bins, col = 'darkgray', border = 'white')
  })
}

# Run the application 
shinyApp(ui = ui, server = server)

Thank you very much!

enter image description here

Insertion this code

ui <- shiny::navbarPage(
  
  title = div(img(src='simulation.jpg',style="margin-top: -14px; padding-right:10px;padding-bottom:10px", height = 60)),
  windowTitle="Simulation",

enter image description here


Solution

  • Would this work? enter image description here

    library(shiny)
    library(shinythemes)
    shinyUI(
        navbarPage(title = div("", img(src = "simulation.jpg", id = "simulation", height = "50px",width = "100px",style = "position: relative; margin:-15px 0px; display:right-align;")), 
                   theme = shinytheme("flatly"), 
                   tabPanel("Simulation",collapsible = TRUE,
                            sidebarLayout(
                                sidebarPanel(
                                    sliderInput("bins",
                                                "Number of bins:",
                                                min = 1,
                                                max = 50,
                                                value = 30)
                                ),
    
                                sidebarLayout(
                                    sidebarPanel(
                                        sliderInput("bins",
                                                    "Number of bins:",
                                                    min = 1,
                                                    max = 20,
                                                    value = 30)
                                    ),
                                    mainPanel(
                                        plotOutput("distPlot")
                                    )
                                )
                            ))
        )
    
    )
    

    enter image description here