如果应用程序能够检测到上次单击或更新的小部件的 ID,那么我为闪亮的应用程序设计所采用的方法将是最简单的。
This https://stackoverflow.com/q/72061061/7742981问题的出现解决了问题。然而,当我使用接受的答案运行 MCVE 时,我根本没有任何反应。
当前代码如下。这本质上是一个链接的问题,并从已接受的答案中进行了明显的替换。
library(shiny)
ui <- fluidPage(
tags$head(
# taken from accepted answer
tags$script(
HTML("$(document).on('shiny:inputchanged', function(event) {
Shiny.setInputValue('last_input', event.name);
});")
)
# through to here
),
numericInput("num1", "Numeric", 0),
textInput("text1", "Text"),
selectInput("select1", "Select", choices = LETTERS[1:4]),
selectInput("selectize1", "Selectize", choices = letters[1:4]),
textOutput("textout")
)
server <- function(input, output, session) {
output$textout <- renderText({
input$last_input
})
}
shinyApp(ui, server)
预期行为:
- 当与 widget 交互时,会显示最后一个交互的 widget 的 id。
观察到的行为:
检查尝试:
- 更新闪亮版本。
- 原始帖子中的其他代码建议 - 没有变化
- 使用...产生一些但不完全的反应性
.ready(function(){$('input').on('shiny:inputchanged'
... 而不仅仅是.on('shiny:inputchanged'
.
我是 R 程序员,不是 JS 程序员。具有这两种技能的人可以建议如何使其发挥作用吗?