我试图从单独的文件建立用户界面,以保持一切有组织,但运行到问题时,采购他们到新的水龙头.下面是一个简单的例子,我源两个文件(这些可以在下面找到)。源代码1是完全好的,但当我添加第二个源代码,第一页将采取UI布局,从,或它去狂暴。也许我遗漏了什么或者这不是我们应该做的。我想这会让一切都很干净。我需要做什么才能正确地从每个选项卡的文件中获取布局?
library(shiny)
library(gridlayout)
library(bslib)
library(dplyr)
ui <- tabsetPanel(
id = "tabset",
tabPanel(title = "PAGE 1", source(file = "~/page_1.R", local = TRUE)$value),
tabPanel(title = "PAGE 2", source(file = "~/page_2.R", local = TRUE)$value),
)
server <- function(input, output) {
# DATA:
x1 <- reactive({runif(input$obs1)})
y1 <- reactive({runif(input$obs1)})
x2 <- reactive({runif(input$obs2)})
y2 <- reactive({runif(input$obs2)})
# PAGE 1
output$test <- renderPlot({
plot1 <- plot(x1(), y1())
plot1
})
# PAGE 2
output$test2 <- renderPlot({
plot2 <- plot(x2(), y2())
plot2
})
output$tbl1 <- renderTable({
tbl <- tibble(x = x2(),
y = y2())
tbl
})
}
shinyApp(ui, server)
第1页文件
grid_page(
layout = c(
"tabpanel tabpanel",
"sidebar plot1"),
row_sizes = c(
"10px",
"1fr"
),
col_sizes = c(
"150px",
"1fr"
),
gap_size = "1rem",
grid_card(
area = "sidebar",
card_header("Settings"),
card_body(
sliderInput("obs1", "First Page OBS:", min = 0, max = 1000, value = 500)
)
),
grid_card(
area = "plot1",
card_body(plotOutput(outputId = "test"))
)
)
第2页文件
grid_page(
layout = c(
"tabpanel tabpanel tabpanel",
"sidebar tbl1 plot2"),
row_sizes = c(
"10px",
"1fr"
),
col_sizes = c(
"150px",
"1fr",
"1fr"
),
gap_size = "1rem",
grid_card(
area = "sidebar",
card_header("Settings"),
card_body(
sliderInput("obs2", "Second Page OBS:", min = 0, max = 1000, value = 500)
)
),
grid_card(
area = "plot2",
card_body(plotOutput(outputId = "test2"))
),
grid_card(
area = "tbl1",
card_body(tableOutput(outputId = "tbl1"))
)
)
1条答案
按热度按时间gstyhher1#
我同意模块是一条路要走,但如果有人想使这一工作,它是可能的删除
grid_page
从这些文件,并使用fluidPage
和grid_container
。然后你就不再需要'tabset'行了,所以例子是这样的。在两个文件上执行此操作,就像我期望的那样。