0

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

Community
  • 1
  • 1
Antonio
  • 1,091
  • 7
  • 24
  • Does this answer your question? [Logo instead of application title Shiny](https://stackoverflow.com/questions/33219885/logo-instead-of-application-title-shiny) – teofil May 14 '20 at 02:06
  • Unfortunately I couldn't. I inserted above the code that was inserted as well as the image. Do you have any idea what the error could be? – Antonio May 14 '20 at 02:43
  • I saw the error friend is in the src. How do I find the directory to place the images on the src? – Antonio May 14 '20 at 03:10
  • You should place the image in a www folder as explained in this [answer](https://stackoverflow.com/a/21998722/13473361). You may also need to split the app.R file in the ui.R and the server.R files. – Gorka May 14 '20 at 03:13

1 Answers1

3

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

Pork Chop
  • 28,528
  • 5
  • 63
  • 77