这是由于shiny使用输入方式的原因。在javascript中,它有一个选项,'debounce'为250ms,这就解释了为什么只有在停止打字四分之一秒后才更新。
您可以覆盖此设置,但似乎需要编写textInput的替代方案。关键部分是javascript中的getRatePolicy函数。
library(shiny)
library(shinyCustom)
textinput_script <- "
<script>
var customTextInputBinding = $.extend({}, Shiny.inputBindings.bindingNames['shiny.textInput'].binding, {
find: function(scope) {
return $(scope).find('input.customTextInput');
},
subscribe: function(el, callback) {
$(el).on('keyup.customTextInputBinding input.customTextInputBinding', function(event) {
callback();
});
$(el).on('focusout.customTextInputBinding', function(event) { // on losing focus
callback();
});
},
unsubscribe: function(el) {
$(el).off('.customTextInputBinding');
},
getRatePolicy: function() {
return {
policy: 'direct'
};
}
});
Shiny.inputBindings.register(customTextInputBinding, 'shiny.customTextInput');
</script>
"
ui <- fluidPage(sidebarLayout(
sidebarPanel(
HTML(textinput_script),
customTextInput("text", label = NULL)
),
mainPanel(textOutput("textout"))
))
server <- function(input, output, session) {
output$textout <- renderText({
input$text
})
}
shinyApp(ui, server)
这是从这里剽窃的,而一般执行此操作的实际指南在这里。
textInput
而不是输出。找不到任何改变这种行为的方法。 - pseudospin