我正在开发一个闪亮的应用程序,在我工作的过程中,我一直在以随意的方式添加数字和表格。我希望有一个更好的框架,以便随着它的进一步发展,我可以灵活地将反应性图形和表格添加到输出中。
目前,我一直在使用 tabPanel 和 Fluidrow 添加额外的汇总表和第二个图。然而我在适应这一点时遇到了困难。例如,我当前生成 3 个绘图,但一次只能绘制 2 个。谁能告诉我一种修改代码以在同一页面上显示所有三个图(distPlot1、distPlot2、distPlot3)和汇总表的方法?理想情况下,将来添加其他表格和图表会很简单。
先感谢您。
我当前的代码如下。
ui.R
library(reshape2)
library(shiny)
library(ggplot2)
# Define UI for application that draws a histogram
fluidPage(
# Application title
titlePanel("Mutation Probability"),
# Sidebar with a slider input for the number of bins
sidebarLayout(
sidebarPanel(
sliderInput("x", "Probability of mutation (per bp):",
min=1/1000000000000, max=1/1000, value=1/10000000),
sliderInput("y", "Size of region (bp):",
min = 10, max = 10000, value = 1000, step= 100),
sliderInput("z", "Number of samples:",
min = 1, max = 100000, value = 1000, step= 10)
),
# Show a plot of the generated distribution
mainPanel(
tabsetPanel(
tabPanel("Plot",
fluidRow(
splitLayout(cellWidths = c("50%", "50%"), plotOutput("distPlot1"), plotOutput("distPlot3"), plotOutput("distPlot3)"))
)),
tabPanel("Summary", verbatimTextOutput("summary"))
)
)
)
)
server.R
server <- function(input, output) {
mydata <- reactive({
x <- input$x
y <- input$y
z <- input$z
Muts <- as.data.frame(rpois(100,(x*y*z)))
Muts
})
output$distPlot1 <- renderPlot({
Muts <- mydata()
ggplot(Muts, aes(Muts)) + geom_density() +xlab("Observed variants")
})
output$distPlot2 <-renderPlot({
Muts <- mydata()
ggplot(Muts, aes(Muts)) + geom_histogram() + xlab("Observed variants")
})
#get a boxplot working
output$distPlot3 <-renderPlot({
Muts <- mydata()
ggplot(data= melt(Muts), aes(variable, value)) + geom_boxplot() + xlab("Observed variants")
})
output$summary <- renderPrint({
Muts <- mydata()
summary(Muts)
})
}