r - Shiny 的 R 移动边栏

标签 r shiny sidebar

我有一个侧边栏如下

  sidebarPanel(
    wellPanel(

      list(tags$head(tags$style("body {background-color: #E0F2F7; }"))),


      helpText("Choose a stock ticker to examine, For example
               ^HSI - Hang Seng, 
               ^N225 - Nikkei 225 and 
               ^FTSE - FTSE 100. 
               Information will be collected from",tags$a(href="https://uk.finance.yahoo.com/lookup", "yahoo finance"),"."),

      textInput("symb", "Symbol", "^FTSE"),
      bsAlert(inputId = "alert_anchor"),

      dateRangeInput("dates", 
                     "Date range",
                     start = "2015-01-01", 
                     end = as.character(Sys.Date())),
      textOutput("DateRange"),
      div(style="display:inline-block",submitButton("Analysis")),
      div(style="display:inline-block",downloadButton('downloadData', 'Download Data')),width=6
      ))

给出以下内容(侧边栏在左侧) enter image description here

但是我想要它,以便在用户上下滚动时侧边栏跟随页面,而不是如图所示左侧有空白的蓝色区域。

enter image description here

这可以在 R Shiny 上实现吗?如果可以,如何实现?

最佳答案

您可以向 sidebarPanel 添加样式参数,将元素位置设置为 fixed。下面是 Shiny 的默认最小示例,稍作修改以说明行为。

library(shiny)

ui <- fluidPage(
  titlePanel("Hello Shiny!"),
  sidebarLayout(
    sidebarPanel(
      style = "position:fixed; width:33%;", # Add this line to your code!
      sliderInput(inputId = "bins",
                  label = "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)
      
    ),
    mainPanel(
      lapply(1:10, function(i) {
        plotOutput(outputId = paste("distPlot", i, sep = "_"))
      })
      
    )
  )
)

server <- function(input, output) {
  
  lapply(1:10, function(i) {
    
    output[[paste("distPlot", i, sep = "_")]] <- renderPlot({
      set.seed(i)
      x    <- rnorm(n = 1000)
      bins <- seq(min(x), max(x), length.out = input$bins + 1)
      
      hist(x, breaks = bins, col = "#75AADB", border = "white",
           xlab = "Waiting time to next eruption (in mins)",
           main = "Histogram of waiting times")
      
    })
  })
}

shinyApp(ui = ui, server = server)

关于r - Shiny 的 R 移动边栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28744382/

相关文章:

r - R 中线性回归的引导标准误差

r - 如何计算单个值的列数?

r - updateSelectInput 标签不接受 HTML 标签?

css - Wordpress 侧边栏小部件 CSS

jquery - 使用 ajax 或 jquery 查询 msn 天气 api 的示例

r - 在 lapply 中增加多个参数

r - 在 Rmarkdown 文档中使用 R 代码添加引用

r - DataTables 也应用列格式来过滤

r - 是否可以从 Shiny 的应用程序创建用户定义的报告?

ios - ios APP中的侧边栏或抽屉导航?