【问题标题】:R Shiny routing the server calls to appropriate functionsR Shiny 将服务器调用路由到适当的函数
【发布时间】:2017-06-17 12:15:19
【问题描述】:

我是 Shiny 的新手,正在尝试使用 Shiny 模块构建一个完整的网络应用程序。我已经查看了内容 https://shiny.rstudio.com/articles/modules.html 但仍然不确定如何将服务器端请求干净地路由到具有配置的给定服务器功能。例如

如果客户端从具有 2 个不同操作的表单发送输入,我试图将相同的处理发送到不同的函数。例如从上面的教程 -

server <- function(input, output, session) {
    datafile <- callModule(csvFile, "datafile",
    stringsAsFactors = FALSE)
  output$table <- renderDataTable({
    datafile()
  })
}

但是,我想根据输入调用不同的模块 (callModule) 不同的函数。

我也查看了 Appsilon 的 http://blog.appsilondatascience.com/rstats/2016/12/08/shiny.router.html,但我不确定这两种方法是否兼容。

【问题讨论】:

    标签: shiny shiny-server


    【解决方案1】:

    该软件包中的一些最新发展可能会对您有所帮助。 shiny.router 现在支持明确指定根据您的请求 URI 调用的函数。即

    router <- make_router(
      route("/",     root_page,  root_callback),
      route("other", other_page, other_callback),
      route("third", other_page, NA)
    )
    

    当你请求/时会调用函数root_callback,当你请求/other_page时会调用函数other_callback,当你请求/third时不会调用额外函数。

    函数 root_callbackother_callback 应该是接受 3 个参数的函数:

    root_callback <- function(input, output, session) {
       # magic happens here
    }
    

    然后您的表单输入将被打包到第一个参数中,您可以根据它继续操作。

    您可能需要咨询the example stated in the repothis little demo app

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-26
      • 2017-09-07
      相关资源
      最近更新 更多