【发布时间】:2017-07-10 08:58:08
【问题描述】:
我设计了一个闪亮的应用程序来更改绘图的 y 限制,以便以我想要的 y 值为中心轻松可视化我的数据(地质时间序列,y 是深度/时间和 x 任何参数)。在界面中,我有不同的输入类型可以在 y 中导航,例如向上和向下按钮和滑块。如果我使用按钮,此滑块会自行更新。但是,如果我单击太快或更改滑块太快(即在绘图刷新之前),应用程序将进入一个循环并在两个 y 值之间振荡。
我尝试在不同的位置使用isolate(),但没有成功,也找不到解决问题的方法。
提前感谢您的帮助:-)
这里是一个例子,快速点击按钮使bug出现;
library(shiny)
ymax <- 100
ymin <- 0
ui <- fluidPage(
sidebarPanel(
h3("See"),
numericInput("yinter", "Vertical interval (m)",
min = 0, max = ymax, value = 50, step = 0.5),
numericInput("movepercent", "Scroll interval (%)",
min = 0, max = 100, value = 15, step = 5),
numericInput("heightNumeric", "Height (m)",
min = ymin, max = ymax, value = ymin, step = 1),
sliderInput("heightSlider","Height (m)",min = ymin, max = ymax,
value = ymin,step=0.01),
actionButton("up","",icon("arrow-up"),
width = "100%"),
actionButton("down","",icon("arrow-down"),
width = "100%",""),
width=2
),
sidebarPanel(
plotOutput("plot1",height = 800)
)
)
server <- function(input, output, clientData, session) {
values <- reactiveValues()
values$i <- 0
observeEvent(input$up, {
values$i <- values$i + input$yinter*(input$movepercent/100)
})
observeEvent(input$down, {
values$i <- values$i - input$yinter*(input$movepercent/100)
})
observeEvent(input$heightSlider, {
values$i <- input$heightSlider
})
observeEvent(input$heightNumeric, {
values$i <- input$heightNumeric
})
observe({
updateNumericInput(session,"heightNumeric",value = values$i)
})
observe({
updateSliderInput(session,"heightSlider",value = values$i)
})
output$plot1 <- renderPlot({
plot(seq(from=0,to=1,by=0.0001),seq(from=0,to=100,by=0.01),
type="l",ylim=c(values$i-input$yinter/2,
values$i+input$yinter/2))
})
}
shinyApp(ui = ui, server = server)
【问题讨论】:
-
我似乎无法在我的电脑上复制您的问题。需要注意的一点是,这些按钮允许您选择滑块范围之外的值。
-
@JarkoDubbeldam 我真的可以。只需尝试尽可能快地单击按钮,然后它就会开始振荡。
-
@SébastienWouters 这只是我在向按钮发送垃圾邮件时注意到的。