r - 侧边栏面板中没有出现闪亮的小部件
问题描述
我shinydashboard::sidebarSearchForm
在一个闪亮的应用程序中使用,并想在它下面放置其他小部件。但是,每当我这样做时,它们都会被推出sidebarPanel
并进入侧边栏下方的空白处。在下面的代码中,materialSwitch
它位于sidebarPanel
但呈现在侧边栏之外。如果您将materialSwitch
上述内容sidebarSearchForm
放在其中sidebarPanel
,则所有小部件都正确包含在侧边栏中。如何确保所有这些小部件都留在侧边栏中?我希望它materialSwitch
位于侧边栏的底部。谢谢!
library(shiny)
library(shinydashboard)
library(shinyWidgets)
ui <- tagList(
navbarPage(
theme = "simplex",
"App",
tabPanel("Do something",
sidebarPanel(
sliderInput("slider", "Select Num:"
,min = 1
,max = 10
,sep = ""
,value = c(1, 10)),
pickerInput(
inputId = "picker",
label = "Select:",
selected = "a",
choices = letters,
options = list(
`actions-box` = TRUE,
size = 10,
`selected-text-format` = "count > 3"
),
multiple = TRUE
),
h5(HTML("<b>Search</b>")),
sidebarSearchForm(textId = "searchText",
buttonId = "searchButton",
label = "Include These"
),
h5(HTML("<b>Additional Options:</b>")),
materialSwitch(inputId = "add",
label = "Add?:?",
value = FALSE,
status = "primary")
),
mainPanel(
tabsetPanel(
tabPanel("Tab",
"text"
)
)
)
)
)
)
server <- function(input, output){
}
解决方案
这种行为的原因
问题源于这样一个事实,即sidebarPanel
创建sidebarSearchForm
标签<form>
和<form>
标签都不能包含其他<form>
标签。例如,在 chrome 中,这种无效HTML
是固定的,我的猜测是这种修复会将元素移出侧边栏。
顺便说一句:sidebarSearchForm
旨在用于 a dashboardSidebar
(不创建<form>
标签。
解决方法
我不是 HTML 专家,所以我不知道是否sidebarSearchForm
需要自己坐<form>
(我过去也没有使用过这个元素)。
假设没有必要将它放在 own<form>
中,您可以sidebarSearchForm
像这样进行调整:
mySidebarSearchForm <- function (textId, buttonId, label = "Search...", icon = shiny::icon("search")) {
div(class = "sidebar-form", div(class = "input-group",
tags$input(id = textId, type = "text", class = "form-control",
placeholder = label, style = "margin: 5px;"),
span(class = "input-group-btn", tags$button(id = buttonId,
type = "button", class = "btn btn-flat action-button",
icon))))
}
(这基本上是原件的副本sidebarSearchForm
替换<form>
by <div>
)
然后 UI 呈现应有的效果:
ui <- tagList(
navbarPage(
theme = "simplex",
"App",
tabPanel("Do something",
sidebarPanel(
mySidebarSearchForm(textId = "searchText",
buttonId = "searchButton",
label = "Include These"
),
actionButton("go", "go")
),
mainPanel(
tabsetPanel(
tabPanel("Tab",
"text"
)
)
)
)
)
)
shinyApp(ui, server = function(...) {})
推荐阅读
- c++ - 如何使用 re2 获取部分匹配的数量
- vuetify.js - 创建表单编号输入并验证它
- javascript - 如何修复元素类型无效:需要一个字符串(对于内置组件)?
- mathematical-optimization - 我怎样才能最好地解决这个优化问题?
- swift - 我想将忘记密码链接添加到 mac 登录屏幕
- python - 如何将网页抓取的文本打印到单行上?
- autohotkey - 如何设置宏以在指定时间在不和谐频道中发送命令?
- mongodb - Mongodb-获取字段匹配特定值的文档的不同计数
- ios - 在 Cocos2dx iOS 项目中添加 Google Firebase
- android - 如何让用户使用毕加索裁剪图像?