嘻嘻,刚刚测试Shiny输入值自动化,感觉还不错哦~
楼主可参考以下代码·,然后修改下updateTextInput()
就行了。
- 倘若要点击按钮后才执行的话,再添加个
actionButton()
。
- 倘若要自动化更新自变量,则添加
invalidateLater()
。
ui <- fluidPage(
sliderInput("n", "Number of observations", 2, 1000, 500),
plotOutput("plot")
)
server <- function(input, output, session) {
observe({
invalidateLater(2000, session)
# Control the value, min, max, and step.
# Step size is 2 when input value is even; 1 when value is odd.
updateSliderInput(session, 'n', value = sample(2:1000, 1),
min = 2, max = 1000)#, step = (val+1)%%2 + 1)
print(paste("The value of input$n is", isolate(input$n)))
})
# Generate a new histogram at timed intervals, but not when
# input$n changes.
output$plot <- renderPlot({
# Re-execute this reactive expression after 2000 milliseconds
invalidateLater(2000)
hist(rnorm(isolate(input$n)))
})
}
shinyApp(ui, server)
}