【问题标题】:Insert Figure in shiny navbarPage在闪亮的 navbarPage 中插入图
【发布时间】:2020-08-30 06:37:33
【问题描述】:

朋友们可以帮我在闪亮的导航栏页面中插入一个图形。我想在我的 navbarPage 中删除书面文字“模拟”并插入附图。这可以在闪亮的情况下进行吗?任何帮助表示赞赏。可执行代码如下。

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)

非常感谢!

插入此代码

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

【问题讨论】:

  • 这能回答你的问题吗? Logo instead of application title Shiny
  • 不幸的是我做不到。我在插入的代码和图像上方插入。你知道错误可能是什么吗?
  • 我看到错误朋友在src。如何找到将图像放在 src 上的目录?
  • 您应该按照answer 中的说明将图像放在 www 文件夹中。您可能还需要在 ui.R 和 server.R 文件中拆分 app.R 文件。

标签: r shiny shinythemes


【解决方案1】:

这行得通吗?

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

)

【讨论】:

  • 是的朋友,您在哪个目录中插入了这张图片以进行闪亮搜索?
  • 它在 ui.R 和 server.R 所在的 www 文件夹中
  • 非常感谢!
  • 嗨猪排,你能告诉我我是怎么找到你上面显示的www 的吗?我没找到。我是通过网站链接做到的。但我想知道找到这个www 的确切目录是什么。例如:C:/Users /Documents/R/...........
  • 您自己在 server.r 和 ui.r 所在的位置创建该目录
猜你喜欢
  • 2017-06-26
  • 2014-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-05
  • 2018-10-22
  • 2019-03-28
相关资源
最近更新 更多