停止更新*输入无效的反应性
我正在寻找一种方法来停止更新*输入
函数在我的Shiny应用程序中的反应性值无效。我希望更新功能仅更改视觉UI组件,而不是基本的反应值。
这是一个reprex:
library(shiny)
ui <- fluidPage(
sliderInput("slide1", "Slider", min = 0, max = 10, value = 5),
sliderInput("slide2", "Slider2", min = 0, max = 10, value = 0),
textOutput("slide2_val")
)
server <- function(input, output, session) {
observe({
updateSliderInput(session, "slide2", value = input$slide1)
}) |>
bindEvent(input$slide1)
output$slide2_val <- renderText({
paste("Value of `slide2`:", input$slide2)
})
}
shinyApp(ui, server)
所需的行为是为input $ slide2
的值,仅在用户与Slide2交互时更改,但是当Slide 1或Slide2与Slide2相互作用时,Slider UI元素要更改。
重要的是,这需要适用于各种输入*
函数。收听点击事件对selectInput
之类的输入不起作用(请参阅我的相关问题)。
I'm looking for a way to stop update*Input
functions from invalidating reactive values in my Shiny app. I want the update function to change only the visual UI component, not the underlying reactive value.
Here's a reprex:
library(shiny)
ui <- fluidPage(
sliderInput("slide1", "Slider", min = 0, max = 10, value = 5),
sliderInput("slide2", "Slider2", min = 0, max = 10, value = 0),
textOutput("slide2_val")
)
server <- function(input, output, session) {
observe({
updateSliderInput(session, "slide2", value = input$slide1)
}) |>
bindEvent(input$slide1)
output$slide2_val <- renderText({
paste("Value of `slide2`:", input$slide2)
})
}
shinyApp(ui, server)
The desired behaviour is for the value of input$slide2
to only change when the user interacts with slide2, but for the slider UI element to change when either slide1 or slide2 are interacted with.
Importantly, this needs to work for a variety of input*
functions. Listening for click events won't work for inputs like selectInput
(see my related issue).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我的最近的另一个问题的答案
我做了一个
supsendfornextflush()
函数以暂时停止更改从发送到Shiny的输入。该功能可用于解决您的
问题也是。
我已经继续将功能放在实验中
shinysususpend 软件包。你可以
从github中安装它:
然后在UI中添加
USESHINYSUSPEND()
,然后调用supstendfornextflush()
从服务器更新
slide2
时:In my recent answer to another question
I made a
suspendForNextFlush()
function to temporarily stop changes to aninput from being sent to Shiny. That function could be used to solve your
problem, too.
I’ve gone ahead and put the function in an experimental
shinysuspend package. You can
install it from GitHub with:
Then include
useShinysuspend()
in the UI, and callsuspendForNextFlush()
when updating
slide2
from the server: