R Shiny:从另一个 Shiny 应用程序内部调用模块会将它们限制在我屏幕的一半
R Shiny: Calling modules from inside another Shiny app confines them to only half my screen
我已经将几个小的 Shiny 应用程序封装到模块中。当从命令行单独调用这些模块时,它们会按预期显示,填满整个页面。我想创建一个应用程序,用户可以从菜单中 select 不同的模块。我一直在尝试使用 navbarPage 和 tabPanel 执行此操作,但模块始终显示在屏幕高度的一半处。
我试过在 divs/boxes 中包装各种元素并更改它们的高度,但它只会更改模块周围容器的高度,而不是模块本身。我对 Shiny 很陌生,我想我一定是误解了模块和调用它们的应用程序之间的关系。
可重现的例子:
WGStableUI <- function(id){ fluidPage(
dataTableOutput(NS(id,"dynamic"))
)
}
WGStableServer <- function(id){
moduleServer(id, function(input, output, session) {
#WGS_tbl <- tbl(connection,"WGS") %>% as_tibble()
#output$dynamic <- renderDataTable(WGS_tbl, options = list(pageLength = 5))
output$dynamic <- renderDataTable(mtcars, options = list(pageLength = 100))
})}
WGStableApp <- function() {
ui <- fluidPage(
WGStableUI("displayWGStable")
)
server <- function(input, output, session) {
WGStableServer("displayWGStable")
}
shinyApp(ui, server)
}
library(shiny)
source("./WGS_table_module.R")
ui <- navbarPage("title",
tabPanel("page1"),
tabPanel("page2",WGStableApp())
)
server <- function(input, output){}
shinyApp(ui,server)
编辑:仍在尝试解决这个问题,我已经意识到只是从另一个应用程序内部调用模块会导致问题,tabPanels 无效。有滚动条,但是我不能改变显示的大小window。同样的事情发生在做:
library(shiny)
ui <- WGStableApp()
server <- function(input, output, session) {
}
shinyApp(ui, server)
我一直不明白为什么会这样,但我确实找到了解决办法。我没有像上面那样将 UI 和服务器模块一起调用,而是创建了另一个模块,分别调用每个 UI 和服务器元素,然后我从应用程序调用了这个新模块。
示例:
menu_ui <- function(id) {
navbarPage("Menu",
tabPanel("WGS Epi Table",WGStableUI(NS(id, "infotable")))
)
}
menu_server <- function(id) {
moduleServer(id, function(input, output, session) {
WGStableServer("infotable")
})
}
demo_menu <- function() {
ui <- fluidPage(menu_ui("demomenu"))
server <- function(input, output, session) {
menu_server("demomenu")
}
shinyApp(ui, server)
}
我已经将几个小的 Shiny 应用程序封装到模块中。当从命令行单独调用这些模块时,它们会按预期显示,填满整个页面。我想创建一个应用程序,用户可以从菜单中 select 不同的模块。我一直在尝试使用 navbarPage 和 tabPanel 执行此操作,但模块始终显示在屏幕高度的一半处。
我试过在 divs/boxes 中包装各种元素并更改它们的高度,但它只会更改模块周围容器的高度,而不是模块本身。我对 Shiny 很陌生,我想我一定是误解了模块和调用它们的应用程序之间的关系。
可重现的例子:
WGStableUI <- function(id){ fluidPage(
dataTableOutput(NS(id,"dynamic"))
)
}
WGStableServer <- function(id){
moduleServer(id, function(input, output, session) {
#WGS_tbl <- tbl(connection,"WGS") %>% as_tibble()
#output$dynamic <- renderDataTable(WGS_tbl, options = list(pageLength = 5))
output$dynamic <- renderDataTable(mtcars, options = list(pageLength = 100))
})}
WGStableApp <- function() {
ui <- fluidPage(
WGStableUI("displayWGStable")
)
server <- function(input, output, session) {
WGStableServer("displayWGStable")
}
shinyApp(ui, server)
}
library(shiny)
source("./WGS_table_module.R")
ui <- navbarPage("title",
tabPanel("page1"),
tabPanel("page2",WGStableApp())
)
server <- function(input, output){}
shinyApp(ui,server)
编辑:仍在尝试解决这个问题,我已经意识到只是从另一个应用程序内部调用模块会导致问题,tabPanels 无效。有滚动条,但是我不能改变显示的大小window。同样的事情发生在做:
library(shiny)
ui <- WGStableApp()
server <- function(input, output, session) {
}
shinyApp(ui, server)
我一直不明白为什么会这样,但我确实找到了解决办法。我没有像上面那样将 UI 和服务器模块一起调用,而是创建了另一个模块,分别调用每个 UI 和服务器元素,然后我从应用程序调用了这个新模块。
示例:
menu_ui <- function(id) {
navbarPage("Menu",
tabPanel("WGS Epi Table",WGStableUI(NS(id, "infotable")))
)
}
menu_server <- function(id) {
moduleServer(id, function(input, output, session) {
WGStableServer("infotable")
})
}
demo_menu <- function() {
ui <- fluidPage(menu_ui("demomenu"))
server <- function(input, output, session) {
menu_server("demomenu")
}
shinyApp(ui, server)
}