Insert Figure in shiny navbarPage

痞子三分冷 提交于 2020-06-23 12:38:07

问题


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!

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",


回答1:


Would this work?

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")
                                )
                            )
                        ))
    )

)



来源:https://stackoverflow.com/questions/61785303/insert-figure-in-shiny-navbarpage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!