我正在尝试学习 rhino 模块来开发 R 闪亮的应用程序,但被这个简单的应用程序困住了:
应用程序/视图/page1.R
box::use(
shiny[moduleServer, textOutput, renderText, NS, div],
shiny.fluent[TextField.shinyInput, Stack]
)
#' @export
ui <- function(id){
ns <- NS(id)
Stack(TextField.shinyInput(ns("page1input"), value = "default value"),
textOutput(ns('page1print'))
)
}
#' @export
server <- function(id) {
moduleServer(id, function(input, output, session){
output$page1print <- renderText(sprintf("Input from above: %s", input$page1input))
})
}
主.R
box::use(
shiny[div, moduleServer, NS, renderUI, tags, uiOutput, renderText],
shiny.fluent[fluentPage]
)
box::use(
app/view/page1
)
#' @export
ui <- function(id) {
ns <- NS(id)
fluentPage(
page1$ui('p1')
)
}
#' @export
server <- function(id) {
moduleServer(id, function(input, output, session) {
page1$server('p1')
})
}
我希望应用程序打印用户的输入,但事实并非如此。有人可以帮忙吗?非常感谢
您忘记在调用中添加命名空间
page1$ui
# main.R
#' @export
ui <- function(id) {
ns <- NS(id)
fluentPage(
page1$ui(ns('p1')) # <- fixed here
)
}
现在
main$server
能够从 page1$ui
读取输入。别担心,每个人都会犯几次这样的错误;)。