简体   繁体   English

具有可重复使用页面的“模块化”闪亮应用程序

[英]“Modular” Shiny App with Reusable Page

I want to design a Shiny app that is "modular" in the sense that I can reuse large parts of it in different applications. 我想设计一个“模块化”的Shiny应用程序,因为我可以在不同的应用程序中重用它的大部分。 The app encompasses a multi-step workflow separated by different pages of a navbarPage or something similar. 该应用程序包含一个由navbarPage或类似内容的不同页面分隔的多步骤工作流。 I basically want to make an entire page, including both UI and server logic, creatable from a pair of functions that I can then reuse in other applications to create the exact same page. 我基本上希望使整个页面(包括UI和服务器逻辑)都可以通过一对函数创建,然后可以在其他应用程序中重复使用以创建完全相同的页面。 The page is for gating flow cytometry data using a custom javascript widget I designed, but that's not important. 该页面用于使用我设计的自定义javascript小部件控制流式细胞仪数据,但这并不重要。

In short, there would be an R file with two functions. 简而言之,将有一个具有两个功能的R文件。 One, 'gatingPageUI', would return a tabPanel element containing all the UI elements of the page. 其中一个“ gatingPageUI”将返回一个tabPanel元素,其中包含页面的所有UI元素。 It would take a 'prefix' argument and name all the inputs and outputs on the page '.gating.widget' or '.channel.x.select' or whatever, to avoid input/output name collisions. 为了避免输入/输出名称冲突,将使用“前缀”参数,并将页面上的所有输入和输出命名为“ .gating.widget”或“ .channel.x.select”。

The second function, 'gatingPageLogic', would take the same 'prefix' argument and assign reactive values to all the outputs and create observers to deal with changes in input. 第二个函数“ gatingPageLogic”将采用相同的“ prefix”参数,并将无功值分配给所有输出,并创建观察者以处理输入中的更改。 It would probably create a reactiveValues object, which would be updated with all the data generated by the page, and either return it or create it in the parent environment. 它可能会创建一个reactValues对象,该对象将使用页面生成的所有数据进行更新,并返回它或在父环境中创建它。

Problem is I do not know how to get and set reactive values from within the server logic function. 问题是我不知道如何从服务器逻辑功能中获取和设置反应性值。 If I pass a reactiveValues object to the function, will reactive objects (observers and reactive outputs) created in the function work correctly with it? 如果我将reactValues对象传递给该函数,在函数中创建的反应对象(观察者和反应输出)是否可以正常使用? For example, I would probably want to pass a ReactiveValues object containing the data set to operate on, can I access that within the function in a reactive way? 例如,我可能想传递一个ReactiveValues对象,该对象包含要操作的数据集,我可以以反应方式在函数内访问该对象吗? What about returning reactive data? 返回反应性数据呢? Can I just return a reactiveValues object or a reactive expression? 我可以只返回一个reactValues对象还是一个反应表达式?

Or is this even the correct pattern to use? 还是这甚至是使用的正确模式?

One approach would be to just use source to include parts of one app in another app: 一种方法是仅使用源代码将一个应用程序的一部分包含在另一个应用程序中:

for(file in list.files(c("../base/tools/app", 
                          "../base/tools/data"),
                          pattern="\\.(r|R)$", full.names = TRUE))
      source(file, local = TRUE)

This approach would allow you to reuse chunks of code in different apps. 这种方法将允许您在不同的应用程序中重用代码块。 Each app is in the same inst/ directory in my case and the code chunk above is in inst/quant. 就我而言,每个应用程序都位于同一inst /目录中,而上面的代码块位于inst / quant中。 quant reuses the code in inst/base and extends it quant重用inst / base中的代码并对其进行扩展

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM