问题描述
我有一个带有模块的大型闪亮应用程序,并且正在R6类中转换其中一些模块。除嵌套模块外,其他所有方法都运行良好:我面临命名空间问题,并且uiOutput无法正常工作。
这是一个可复制的示例。类ClassTest是类层次结构中的最后一个类。它可以直接由App调用,也可以通过Temp类调用。在后一种情况(嵌套类)中,uiOutput中包含的元素不起作用。
library(shiny); library(R6)
ClassTest = R6Class(
"ClassTest",public = list(
# attributes
id = NULL,# initialize
initialize = function(id){
self$id = id
},# UI
ui = function(){
ns = NS(self$id)
tagList(
h4('Test class'),uiOutput(ns('showText'))
)
},# server
server = function(id){
moduleServer(id,function(input,output,session){
ns = session$ns
output$showText <- renderUI({
print('In showText <- renderUI')
tagList(
p('I am the showText renderUI of the Test class')
)
})
}
)
},call = function(input,ouput,session){
self$server(self$id)
}
)
)
#----------------------------------------------------------
Temp = R6Class(
"Temp",public = list(
# attributes
temp = NULL,id = NULL,# initialize
initialize = function(id){
self$id = id
self$temp <- ClassTest$new('testTiers')
},# UI
ui = function(){
ns = NS(self$id)
tagList(
uiOutput(ns('showTestClass'))
)
},session){
ns = session$ns
output$showTestClass <- renderUI({
self$temp$ui()
})
})
},session){
self$server(self$id)
}
)
)
#----------------------------------------------------------
App = R6Class(
"App",classT = NULL,# initialize
initialize = function(){
self$temp = Temp$new('temp')
self$classT = ClassTest$new('directTest')
},# UI
ui = function(){
tagList(
h3('Call by another class'),self$temp$ui(),hr(),h3('Direct call'),self$classT$ui()
)
},# server
server = function(input,session){
self$temp$call()
self$classT$call()
}
)
)
app = App$new()
shiny::shinyApp(app$ui(),app$server)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)