【问题标题】:Where to put the if condition in shiny dashbord在闪亮的仪表板中放置 if 条件的位置
【发布时间】:2019-08-08 19:21:14
【问题描述】:

这是一个一般性问题,将 if 条件放入仪表板的服务器部分的更好方法

第一个选项

server <- function(input, output, session) {

df <-reactive({

    if else condition 

    return(df)
  })

output$table <- renderTable(df())

}

runApp(shinyApp(ui, server),launch.browser = TRUE)

第二个选项

server <- function(input, output, session) {

output$table <- renderTable(if else condition) ## put the if condition direct inside render 

}

runApp(shinyApp(ui, server),launch.browser = TRUE)

没有代码,这只是为了我的知识

想知道最好的方法。

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    如果您在多个地方需要 df(),选项 1 很有用,这样您就不必在任何地方重复 if else。使用这种方法,您的所有数据操作都集中在一个地方,非常适合调试和维护。

    如果您在某些 render* 中只使用一次 df(),则选项 2 没问题,但这种情况只会出现在非常简单的应用程序中。

    总体而言,选项 1 更好,因为它更通用,当您开始开发复杂的应用程序时,无论如何您最终都会使用该方法

    【讨论】:

      猜你喜欢
      • 2019-10-08
      • 1970-01-01
      • 2019-07-02
      • 2019-07-26
      • 2015-04-22
      • 1970-01-01
      • 2020-06-10
      • 2017-01-14
      • 1970-01-01
      相关资源
      最近更新 更多