我为uiOutput动态生成fluidrows,因为用户选择将决定有多少行。对于每一行,我有3列--两列是文本,第三列是图。
我已经把课文写好了,但我还在苦苦思索怎么才能把情节写进去。
在下面的reprex中,它是相同的图,但在我的实际示例中,我需要使用一个表,而不是传递给.x ()的表,但需要根据其中一个map值对其进行过滤。
library(tidyverse)
ui <- fluidPage(
uiOutput("row_mt")
)
server <- function(input, output) {
output$row_mt <- renderUI({
mt_list <- mtcars %>%
rownames_to_column(var = "model") %>%
rowwise() %>%
group_split() %>%
map(~{
tagList(fluidRow(
column(4,
.x$model),
column(4,
.x$mpg),
column(4,
mtcars %>%
filter(cyl == .x$cyl) %>%
ggplot(aes(x = mpg, y = cyl)) + geom_point())
),
br()
)
})
tagList(mt_list)
})
}
shinyApp(ui, server)发布于 2021-08-16 21:23:14
您应该尝试使用renderPlot创建绘图,然后使用plotOutput在renderUI中显示它。
试试这个
server <- function(input, output) {
output$myplot <- renderPlot({
mtcars %>%
rownames_to_column(var = "model") %>%
rowwise() %>%
group_split() %>%
map(~{
mtcars %>%
filter(cyl == .x$cyl) %>%
ggplot(aes(x = mpg, y = cyl)) + geom_point()
})
})
output$row_mt <- renderUI({
mt_list <- mtcars %>%
rownames_to_column(var = "model") %>%
rowwise() %>%
group_split() %>%
map(~{
tagList(fluidRow(
column(4,
.x$model),
column(4,
.x$mpg),
column(4,
plotOutput("myplot", height=100, width=100))
),
br()
)
})
tagList(mt_list)
})
}

https://stackoverflow.com/questions/68808718
复制相似问题