如何解决如何在多个嵌套模块中显示带有 DT 的动态 tabPanels
我真的需要有关以下代码的帮助,我使用 2 个嵌套模块按某些列在多个 sampledata
(在 tabPanels
内)中显示 tabsetPanel
,但表格未显示,我还没有发现里面有任何错误。
PS:这只是一个可重现的例子,sampledata
是用户在真实场景中上传的
library(shiny)
library(shinydashboard)
library(DT)
ui <- function() {
dashboardPage(
dashboardHeader(title = "abc"),dashboardSidebar(uIoUtput("sidebarpanel")),dashboardBody(uIoUtput("body")))
}
server <- function(input,output,session) {
output$sidebarpanel <- renderUI({
tags$div(
sidebarMenu(id = "tabs",menuItem("Data",tabName = "data"))
)
})
output$body <- renderUI({
tabItems(ui_data1("data1",tabName = "data"))
})
input_data1 <- new.env()
input_data1$a <- reactive(1)
input_data1$b <- reactive(2)
input_data2 <- server_data1("data1",input_data1)
}
ui_data1 <- function(id,tabName){
ns <- NS(id)
tabItem(tabName = tabName,uIoUtput(ns("body")))
}
server_data1 <- function(id,input_data1) {
ns <- NS(id)
moduleServer(id,function(input,session) {
output$body <- renderUI({
tabsetPanel(
ui_data2(ns("info1"),"Info1")
)
})
data2 <- new.env()
data2$input_data2 <- server_data2("info1",input_data1)
return(data2)
})
}
ui_data2 <- function(id,title) {
ns <- NS(id)
tabPanel(title = title,uIoUtput(ns("body")))
}
server_data2 <- function(id,session) {
c <- eventReactive(input_data1$a(),{
2
})
sampledata <- reactive(mtcars)
output$body <- renderUI({
all_cyl <- unique(sampledata()$cyl)
tbl_by_cyl <- lapply(seq_along(all_cyl),function(i) {
tabPanel(all_cyl[i],column(12,br(),Box(width = "auto",DT::dataTableOutput(ns(paste0("cyl",i)),width = "100%"))))
})
do.call(tabsetPanel,tbl_by_cyl)
})
observe({
sampledata <- sampledata()
all_cyl <- unique(sampledata$cyl)
lapply(seq_along(all_cyl),function(i) {
output[[paste0("cyl",i)]] <- DT::renderDataTable({
datatable(sampledata[sampledata$cyl == all_cyl[i],])
})
})
})
return(sampledata)
})
}
shinyApp(ui,server)
解决方法
你们很亲近。您只需要在 var string = "8% of 25 is the same as <img src=\"/someimage.png\" class=\"limit\">There are no heroes in a punk rock band <img src=\"/someimage.png\" class=\"limit\">"
val arraySearchInTheStringVariableAbove = arrayOf(
"<img src=\"/someimage.png\" class=\"limit\">","<img src=\"/someimage.png\" class=\"limit\">"
)
val arrayReplacementInTheStringVariableAbove = arrayOf(
"<img src=\"/someimage.png\" class=\"another-limit\" data-id=\"1\">","<img src=\"/someimage.png\" class=\"another-limit\" data-id=\"2\">"
)
arraySearchInTheStringVariableAbove.forEachIndexed { index,it ->
string = string.replace(it,arrayReplacementInTheStringVariableAbove[index])
}
println(string)
和 ns <- session$ns
中使用 server_data1
。试试这个
server_data2
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。