模态对话框打开时默认打开下拉菜单
Dropdown menu opened by default when modal dialog opens
以此 thread 为例,我在 select table 列中添加了一个下拉菜单。
但是,当模式打开时,列表菜单应该关闭。
有没有办法使用 javascript 或其他方式让模式对话框打开时默认关闭下拉菜单?
library(shiny)
library(shinyjs)
library(shiny.semantic)
library(DT)
modal.js <- "$('.ui.modal').modal('show');
$('#my_table').show().trigger('shown');"
ui <- semanticPage(
suppressDependencies("bootstrap"),
useShinyjs(),
div(
class = "ui modal",
div(class = "header", "Modal header"),
div(class = "content",
div(class = "ui raised segment",
selectInput(inputId = "picker",
label = "Select column",
choices = names(iris),
selected = names(iris)[-1],
multiple=T),
br(),
DT::dataTableOutput("my_table")))
),
div(class = "ui basic button action-button", id = "open_modal", "Open modal ui")
)
server <- function(input, output, session) {
output$my_table = DT::renderDataTable(head(iris[,input$picker]))
observeEvent(input$open_modal, runjs(modal.js))
}
shinyApp(ui, server, options = list(launch.browser = TRUE))
尝试 selectizeInput
中的选项 openOnFocus = FALSE
,如下所示。
selectizeInput(inputId = "picker",
label = "Select column",
choices = names(iris),
selected = names(iris)[-1],
options = list(openOnFocus = FALSE),
multiple=T),
以此 thread 为例,我在 select table 列中添加了一个下拉菜单。
但是,当模式打开时,列表菜单应该关闭。
有没有办法使用 javascript 或其他方式让模式对话框打开时默认关闭下拉菜单?
library(shiny)
library(shinyjs)
library(shiny.semantic)
library(DT)
modal.js <- "$('.ui.modal').modal('show');
$('#my_table').show().trigger('shown');"
ui <- semanticPage(
suppressDependencies("bootstrap"),
useShinyjs(),
div(
class = "ui modal",
div(class = "header", "Modal header"),
div(class = "content",
div(class = "ui raised segment",
selectInput(inputId = "picker",
label = "Select column",
choices = names(iris),
selected = names(iris)[-1],
multiple=T),
br(),
DT::dataTableOutput("my_table")))
),
div(class = "ui basic button action-button", id = "open_modal", "Open modal ui")
)
server <- function(input, output, session) {
output$my_table = DT::renderDataTable(head(iris[,input$picker]))
observeEvent(input$open_modal, runjs(modal.js))
}
shinyApp(ui, server, options = list(launch.browser = TRUE))
尝试 selectizeInput
中的选项 openOnFocus = FALSE
,如下所示。
selectizeInput(inputId = "picker",
label = "Select column",
choices = names(iris),
selected = names(iris)[-1],
options = list(openOnFocus = FALSE),
multiple=T),