r - 带引导程序的 Shiny 中并排图的动态数量
问题描述
我使用此示例在我的 Shiny 应用程序中生成动态数量的图。
问题是我需要这些图以响应方式并排填充,而不是在彼此下方填充:即动态使用可用的 Bootstrap 列。
我尝试在声称这样做的页面下方进一步关注评论,但我无法使其正常工作并且不遵循代码(例如,放置plotOutput
并且renderPlot
看起来很奇怪)。
我设法使用后一种方法使响应式网格正常工作,但图形没有出现在页面上(它们出现在 RStudio 控制台的图像窗口中)。
我已经搜索但找不到更多关于动态绘图数量的响应网格的信息。我需要使用基本图形,并且不喜欢layout
用来设置整个绘图空间,因为我已经在使用layout
在每个主绘图中绘制多个绘图。
这是第一个链接中用于绘制动态数字数量的代码。我希望地块与响应的行数并排填充。
max_plots <- 12
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
headerPanel("Dynamic number of plots"),
sidebarPanel(
sliderInput("n", "Number of plots", value=1, min=1, max=5)
),
mainPanel(
# This is the dynamic UI for the plots
uiOutput("plots")
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
# Insert the right number of plot output objects into the web page
output$plots <- renderUI({
plot_output_list <- lapply(1:input$n, function(i) {
plotname <- paste("plot", i, sep="")
plotOutput(plotname, height = 280, width = 250)
})
# Convert the list to a tagList - this is necessary for the list of items
# to display properly.
do.call(tagList, plot_output_list)
})
# Call renderPlot for each one. Plots are only actually generated when they
# are visible on the web page.
for (i in 1:max_plots) {
# Need local so that each item gets its own number. Without it, the value
# of i in the renderPlot() will be the same across all instances, because
# of when the expression is evaluated.
local({
my_i <- i
plotname <- paste("plot", my_i, sep="")
output[[plotname]] <- renderPlot({
plot(1:my_i, 1:my_i,
xlim = c(1, max_plots),
ylim = c(1, max_plots),
main = paste("1:", my_i, ". n is ", input$n, sep = "")
)
})
})
}
}
# Run the application
shinyApp(ui = ui, server = server)
欣赏任何提示
解决方案
推荐阅读
- spring - 在 customReaderItem 中管理 I/O 和 POI 异常
- java - 为 playframework 创建自定义路由处理程序
- node.js - Socket.io - 他们的会话管理有多安全?
- raspberry-pi - 在 Raspberry Pi 4 上的 Docker Compose 中运行 Elastic Stack
- django - 有没有办法为 Django 缓存锁设置过期时间?
- c++ - 如何在 Google Test API 中运行 TEST 函数
- swift - 应用程序和模拟器上的错误未启动,Xcode 12.2
- r - 在 R 鼠标包中,我如何找到用于插补的树中的节点数?
- javascript - 群聊聊天应用的架构设计。我无法按时间顺序查询聊天室
- ansible - if else 和 if else 在 ansible 模板中不起作用