我有一个侧边栏如下
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
))
给出以下内容(侧边栏在左侧)
但是我想要它,以便在用户上下滚动时侧边栏跟随页面,而不是如图所示左侧有空白的蓝色区域。
这可以在 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/