【发布时间】:2019-02-18 04:22:27
【问题描述】:
我正在使用来自这个问题的javascript:SO
它适用于按钮,但我也想禁用 sliderInput、selectInput 和 textInput 之类的东西。
我试图用“输入”替换“按钮”,这确实禁用了textinput 字段。我想知道是否有一种方法可以一次性禁用所有元素。
更大的问题是:
当您打开 dropdownbutton 时,关闭按钮通常应该删除 modal dialog,以防 javascript 标记从下面的演示应用程序中删除。但是,当脚本在应用程序中时,关闭按钮由于某种原因不再起作用。它仍然打印文本命令,这意味着它被观察到了,但模式没有关闭。对话框中的另一个按钮仍然正常工作。
应用程序:
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
h3('Disable buttons while running'),
actionButton('btn_run','Run long process'),
hr(),
h3('Inputs'),
actionButton('btn1','Button 1'),
hr(),
textInput('text1', 'Text1',"my text:"),
hr(),
selectInput('select1', 'Selectinput', choices = c('A', 'B', 'C'), selected = 'A'),
hr(),
h5('Dropdown'),
dropdownButton(inputId = "MyDropDown",
h3("This is a dropdown"),
actionButton('btn_run2','Run other long process'),
fluidRow(actionButton( "CloseDropDown", "Close"), style = "float: right; margin-right:10px"),
icon = icon("tasks"),
tooltip = tooltipOptions(title = "Click to open"), width = "500px"),
hr(),
sliderInput('slid3','Slider 1',min=0,max=1,value=0.5),
tags$script(HTML("$(document).on('shiny:busy', function() {
var inputs = document.getElementsByTagName('button');
console.log(inputs);
for (var i = 0; i < inputs.length; i++) {
inputs[i].disabled = true;
}
});
$(document).on('shiny:idle', function() {
var inputs = document.getElementsByTagName('button');
console.log(inputs);
for (var i = 0; i < inputs.length; i++) {
inputs[i].disabled = false;
}
})" ))
)
server <- function(input, output, session){
observeEvent(input$btn_run,{
Sys.sleep(5)
})
observeEvent(input$btn_run2,{
Sys.sleep(5)
})
observeEvent(input$CloseDropDown, {print('closing?')
toggleDropdownButton(inputId = 'MyDropDown') })
}
shinyApp(ui = ui, server = server)
【问题讨论】:
标签: javascript r shiny dropdownbutton