Может быть так:
library(shiny)
textInput2 <- function(inputId, label, value = "", width = NULL,
placeholder = NULL, onkeydown = NULL){
input <- textInput(inputId, label, value, width, placeholder)
input$children[[2]] <-
htmltools::tagAppendAttributes(input$children[[2]], onkeydown = "%s")
tag <- as.character(input)
HTML(sprintf(tag, onkeydown))
}
js <- "Shiny.setInputValue('jsrow', [event.keyCode,event.timeStamp]);
return !((event.which >=48 && event.which <= 57)
|| event.which == 8||(event.which >=37 && event.which <= 40)||(event.which >=33 && event.which <= 34)||event.which == 46
||event.which == 45||event.which == 9||event.which == 13||event.which == 32||(event.which >=16 && event.which <= 18)||event.which == 189
||event.which == 173||(event.which >=112 && event.which <= 123)||event.which == 144||(event.which >=96 && event.which <= 105))
;
"
ui <- fluidPage(
textInput2("textinput", "Enter text:", onkeydown = js)
)
server <- function(input, output){
observeEvent(input$jsrow, {
print(paste0("Value of input is ", input$jsrow[1]))
})
}
shinyApp(ui, server)
А в модуле просто используйте ns
как обычно.
EDIT
js <- function(id) {sprintf("Shiny.setInputValue('%s_jsrow', [event.keyCode,event.timeStamp]);
return !((event.which >=48 && event.which <= 57)
|| event.which == 8||(event.which >=37 && event.which <= 40)||(event.which >=33 && event.which <= 34)||event.which == 46
||event.which == 45||event.which == 9||event.which == 13||event.which == 32||(event.which >=16 && event.which <= 18)||event.which == 189
||event.which == 173||(event.which >=112 && event.which <= 123)||event.which == 144||(event.which >=96 && event.which <= 105));", id)}
ui <- fluidPage(
textInput2("textinput", "Enter text:", onkeydown = js("textinput"))
)
server <- function(input, output){
observeEvent(input$textinput_jsrow, {
print(paste0("Value of input is ", input$textinput_jsrow[1]))
})
}