R Shiny将服务器调用路由到适当的函数

时间:2017-06-17 12:15:20

标签: shiny shiny-server

我是Shiny的新手,并试图使用闪亮的模块构建一个完整的网络应用程序。我已经审查了内容 https://shiny.rstudio.com/articles/modules.html 但仍不确定如何通过配置将服务器端请求干净地路由到给定的服务器功能。 e.g。

如果客户端从表单发送输入,该表单有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,但我不确定这两种方法是否兼容。

1 个答案:

答案 0 :(得分:0)

该软件包中的一些最新进展可能会为您提供帮助。 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_callback时将调用函数/other_page,而在您请求{{1 }}。

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

other_callback

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

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