html - 如何在使用 navbarpage 的 Shiny App 中使用 html 自动将元素移动到页面/视图的底部?
问题描述
我正在为我的 Shiny 应用程序使用导航栏页面。我想要一个元素,在我的例子中是一个 h2 标题元素,自动移动到侧边栏面板的底部。我知道通过将 float 属性应用于 h2 元素标题,我可以在侧边栏面板的左侧或右侧产生我想要的效果。但是,我还没有找到一种方法来产生类似的效果来自动将 h2 元素移动到页面/视图的底部。任何指向正确方向的指针都受到高度赞赏。
我试过添加跨度,但我没有让它工作。
library(shiny)
library(shinyWidgets)
if (interactive()) {
ui <- navbarPage(
title = "SIMULATION",
id = "tabs",
selected = "HOME",
tabPanel(
"HOME",
sidebarLayout(
sidebarPanel(
width = 4,
h2("Standard Normal Distribution Simulation"),
numericInput("num", label = "Enter the number of observations", value = 100),
actionButton("calc", "Draw Plot", icon = icon("calculator")),
h2("Created with Shiny", style = "color:green; float:right;")
),
# paste0(h1("Plot of Normal Distribution:"), h2("mean: std:")),
mainPanel(
h1("Plot of Standard Normal Distribution"),
plotOutput("sim")
) # mainPanel
) # sidebar layout
) # tab panel
)
server <- function(input, output, session) {
output$sim <- renderPlot({
if (input$calc == 0){
return()
}
isolate({
# Plot of Random Points
vals <- rnorm(input$num)
plot(density(vals), main = "Normal Distribution")
})
})
}
shinyApp(ui, server)
}
解决方案
基本上你可以先看看这是如何在没有闪亮的 HTML 中完成的:如何将我的 div 定位在其容器的底部?.
在那里你可以看到你需要一个容器来定位元素。您可以尝试使用现有元素之一,也可以创建一个新元素div
以避免弄乱当前设置。
我选择创建一个新容器:
div(style = "height:800px; position:relative;", ... )
我在那里定位底部元素:
div(style = "position: absolute; bottom: 0;",
h4("I am at the bottom of a 800px div container.")
可重现的代码:
library(shiny)
ui <- navbarPage(
title = "SIMULATION",
id = "tabs",
selected = "HOME",
tabPanel(
"HOME",
div(style = "height:800px; position:relative;",
sidebarLayout(
sidebarPanel(
width = 4,
h5("Sidebar Panel")
),
mainPanel(
h5("Main Panel")
) # mainPanel
),
h4("I am at the bottom right of a height:800px div container.",
style = "position: absolute; bottom: 0;right:0;")
)
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
推荐阅读
- xamarin - 无法使用仪器服务启动应用程序。将尝试使用 gdb 服务启动应用程序
- javascript - 如何使用 Masonry js 和 Rails 无休止的分页
- javascript - 在 Angular 组件中获取标签
- graphql - 为什么我的 graphQL 查询返回的结果没有 `where` 过滤器?
- python - Matplotlib x 轴动态范围更新
- woocommerce - woocomerce 订单状态更改后,请勿向客户发送电子邮件
- excel - 如何计算 Excel (Calc) 中的条纹,范围不断变化
- c# - 文件描述错误的 Openfiledialog 问题
- java - 在动态创建的卡片视图上,如果按下特定于卡片的删除按钮,如何删除单个卡片?
- bash - 在 Catalina 上使用 Anaconda 和 zsh