[英]Non-reactive scope in Shiny
在我的Shiny App中,有两个输入:观察值(一个整数)和颜色(一个在红色,绿色和蓝色之间选择的字符)。 还有一个“ GO!” 操作按钮。
使用以下哪个Shiny函数以:
我希望能为代码提供最大清晰度的解决方案。
请参阅下面我的一个isolate
未成功尝试。
# DO NOT WORK AS EXPECTED
# Define the UI
ui <- fluidPage(
sliderInput("obs", "Number of observations", 0, 1000, 500),
selectInput('color', 'Histogram color', c('red', 'blue', 'green')),
actionButton("goButton", "Go!"),
plotOutput("distPlot")
)
# Code for the server
server <- function(input, output) {
output$distPlot <- renderPlot({
# Take a dependency on input$goButton
input$goButton
# Use isolate() to avoid dependency on input$obs
data <- isolate(rnorm(input$obs))
return(hist(data, col=input$color))
})
}
# launch the App
library(shiny)
shinyApp(ui, server)
像这样吗 单击按钮后,它将仅更新data()
变量。 您可以在此处阅读observeEvent
和eventReactive
rm(list = ls())
# launch the App
library(shiny)
ui <- fluidPage(
sliderInput("obs", "Number of observations", 0, 1000, 500),
selectInput('color', 'Histogram color', c('red', 'blue', 'green')),
actionButton("goButton", "Go!"),
plotOutput("distPlot")
)
# Code for the server
server <- function(input, output) {
data <- eventReactive(input$goButton,{
rnorm(input$obs)
})
output$distPlot <- renderPlot({
return(hist(data(), col=input$color))
})
}
shinyApp(ui, server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.