想检查我们是否可以同时使用Flexidashboard和Normal仪表板。
例如:在Tab1中,我需要Flexidashboard,在Tab 2中,我需要一个Normal仪表板。我在一个标签中有以下代码。
但是我需要将Flexdashboard合并到另一个选项卡中。这可能吗?
df <- structure(
list(
A = structure(
c(1L, 4L, 6L, 1L, 8L, 2L, 7L, 3L,
5L, 5L, 1L, 8L, 2L, 7L, 2L),
.Label = c("asd", "dfg", "fgdsgd",
"fsd", "gdfgd", "gs", "sdfg", "sf"),
class =
"factor"
),
B = c(
29L,
24L,
46L,
50L,
43L,
29L,
32L,
24L,
35L,
39L,
33L,
47L,
53L,
26L,
31L
),
C = structure(
c(8L, 5L, 1L, 6L, 3L, 2L, 9L, 7L, 6L, 3L,
2L, 9L, 8L, 8L, 4L),
.Label = c("asd", "er", "fg", "gf", "gfd",
"gfg", "qw", "sf", "tr"),
class = "factor"
),
D = c(
36L,
56L,
39L,
26L,
56L,
35L,
27L,
31L,
33L,
45L,
34L,
27L,
43L,
40L,
56L
),
E = structure(
c(9L, 4L, 3L, 4L, 2L, 7L, 10L, 8L, 6L, 2L, 1L,
10L, 9L, 9L, 5L),
.Label = c("er", "fg", "g", "gd", "gf", "gfg",
"gtd", "qw", "sf", "tr"),
class = "factor"
),
F = c(
44L,
34L,
37L,
23L,
37L,
51L,
28L,
36L,
33L,
31L,
39L,
43L,
25L,
37L,
43L
),
num = 1:15
),
row.names = c(NA,-15L),
class = "data.frame"
)
theNames <- names(df)
MyList <- vector(mode = "list")
for (i in theNames) {
MyList[[i]] <- df[, i]
}
library(ggplot2)
library(dplyr)
library(shiny)
ui <- fluidPage(tabsetPanel(tabPanel(
"Factor_Bivariate_Analysis",
sidebarLayout(sidebarPanel(
fluidRow(
column(h6(
selectInput(
"se4",
"Factors under the
datasets",
choices = c("", "Values", "Data table")
)
), width = 5, offset =
0),
br(),
column(h6(
actionButton("Val", "See the Values", width =
200, offset =
-1)
), width = 5, offset = 0),
br(),
column(h6(
selectInput("state", "Filters", choices = c("", MyList))
), width = 5, offset = 0)
), width =
1000
),
mainPanel(
uiOutput("plot")
# plotOutput(
# "Plot4", width = "1000px", height =
# "1000px"
# ), dataTableOutput("Plot5")
))
)))
server <- function(input, output, session) {
f_data <- reactive({
wanted_case <- input$state
cat("selected case ", wanted_case, "\n\n")
if (wanted_case == "") {
fd <- df
} else {
fd <-
df %>% filter_if(.predicate = is.factor,
.vars_predicate = any_vars (. ==
wanted_case))
print(fd)
}
return(fd)
})
Plot4 <- reactive({
if (input$se4 == "Values") {
print(
ggplot(data =
f_data(), aes(
x = num, y = B, fill = A
)) + geom_line() + facet_wrap(
"A",
ncol = 1,
nrow = 8,
scales =
"free"
)
)
} else if (input$se4 == "NULL") {
""
}
})
output$Plot4 <- renderPlot({
Plot4()
})
Plot5 <- reactive({
if (input$se4 == "Data table") {
print(data.frame(df))
} else if (input$se4 == "NULL") {
""
}
})
output$Plot5 <- renderDataTable({
Plot5()
})
observe({
req(input$se4)
switch(input$se4,
Values = {
output$plot <- renderUI({
plotOutput(
"Plot4", width = "1000px", height =
"1000px"
)
})
},
"Data table" = {
output$plot <- renderUI({
dataTableOutput("Plot5")
})
})
})
}
shinyApp(ui, server)