【问题标题】:Is it possible to use reactive function into another reactive function in r shiny?是否可以将反应函数用于 r shiny 中的另一个反应函数?
【发布时间】:2016-11-16 12:51:06
【问题描述】:

例如:

        data_cbs <- reactive({ 
        "code"
        })

        model <- reactive({
                data <- data_cbs()
                + "code"    
        })

是否可以在R shiny 中使用以下结构?

知道data_cbs()model 由3-4 个“else-if”语句组成可能很重要。

【问题讨论】:

  • 你应该使用data作为data()
  • @PorkChop 抱歉,打错字了。请再看一遍。
  • 是的,您可以这样做,就像管道一样。此外,您可以将model 绑定到eventReactive,以便它仅在data_cbs 完成时响应

标签: r shiny reactive-programming


【解决方案1】:

这是一个单脚本示例,表明这确实有效并且可以玩弄:

# Global variables can go here
n <- 200


# Define the UI
ui <- bootstrapPage(
  checkboxInput('random', 'randomize'),
  plotOutput('plot')
)


# Define the server code
server <- function(input, output) {

  checkRandom <- reactive({
    if( input$random ){
      data <- runif(n)
    }else {
      data <- seq(1, n)
    }
    return(data)
  })

  output$plot <- renderPlot({
    plot(checkRandom())
  })
}

# Return a Shiny app object
shinyApp(ui = ui, server = server)

【讨论】:

    猜你喜欢
    • 2020-11-30
    • 2019-12-17
    • 1970-01-01
    • 2018-06-23
    • 1970-01-01
    • 1970-01-01
    • 2014-09-06
    • 1970-01-01
    • 2018-08-20
    相关资源
    最近更新 更多