首页 > 解决方案 > 闪亮:文本框自动调整大小文本,而不仅仅是字符串

问题描述

我想创建 4 个相等的文本框,描述上面的照片

ui1 <- (fluidPage(fluidRow(splitLayout(cellWidths = c("25%", "25%", "25%", "25%"), 
                                      tags$img(src = "Photo1.jpg", width = "100%"), 
                                      tags$img(src = "Photo2.jpg", width = "100%"), 
                                      tags$img(src = "Photo3.jpg", width = "100%"),
                                      tags$img(src = "Photo4.jpg", width = "100%"))),
                 fluidRow(splitLayout(cellWidths = c("25%", "25%", "25%", "25%"), 
                                      tags$h5("Photo 1", align = 'center', style = "color:#00A69C"), 
                                      tags$h5("Photo 2", align = 'center', style = "color:#00A69C"), 
                                      tags$h5("Photo 3", align = 'center', style = "color:#00A69C"), 
                                      tags$h5("Photo 4", align = 'center', style = "color:#00A69C"))),
                 fluidRow(splitLayout(cellWidths = c("25%", "25%", "25%", "25%"),
                                      wellPanel(tags$p("Photo 1 is text text text text text text text text text text text text text text text text text text text text")),
                                      wellPanel(tags$p("Photo 2 is text text text text text text text text text text text text text text text text text text text text")), 
                                      wellPanel(tags$p("Photo 3 is text text text text text text text text text text text text text text text text text text text text")), 
                                      wellPanel(tags$p("Photo 4 is text text text text text text text text text text text text text text text text text text text text"))))))


server1 <- (function(input, output){})

shinyApp(ui = ui1, server = server1)

如果我在我的 UI 中运行此代码,我只会得到最后一部分的文本字符串,并且我必须使用水平滚动条来查看我的其余文本。相反,我想要的是我的 wellPanel 会自动调整到文本的大小,并且我不必再滚动了。

标签: rstringtextshinyoutput

解决方案


我使用该column函数而不是splitLayout文本部分的函数,它可以工作。

library(shiny)   
ui1 <- (fluidPage(fluidRow(splitLayout(cellWidths = c("25%", "25%", "25%", "25%"), 
                                       tags$img(src = "Photo1.jpg", width = "100%"), 
                                       tags$img(src = "Photo2.jpg", width = "100%"), 
                                       tags$img(src = "Photo3.jpg", width = "100%"),
                                       tags$img(src = "Photo4.jpg", width = "100%"))),
                  fluidRow(splitLayout(cellWidths = c("25%", "25%", "25%", "25%"), 
                                       tags$h5("Photo 1", align = 'center', style = "color:#00A69C"), 
                                       tags$h5("Photo 2", align = 'center', style = "color:#00A69C"), 
                                       tags$h5("Photo 3", align = 'center', style = "color:#00A69C"), 
                                       tags$h5("Photo 4", align = 'center', style = "color:#00A69C"))),
                  fluidRow(
                    column(width = 3,wellPanel(tags$p("Photo 1 is text text text text text text text text text text text text text text text text text text text text"))),
                    column(width = 3,wellPanel(tags$p("Photo 2 is text text text text text text text text text text text text text text text text text text text text"))), 
                    column(width = 3,wellPanel(tags$p("Photo 3 is text text text text text text text text text text text text text text text text text text text text"))), 
                    column(width = 3,wellPanel(tags$p("Photo 4 is text text text text text text text text text text text text text text text text text text text text"))))

                  ))


server1 <- (function(input, output){})

shinyApp(ui = ui1, server = server1)

推荐阅读