【问题标题】:how to change the text by change the slides in shiny如何通过更改闪亮的幻灯片来更改文本
【发布时间】:2020-09-19 10:00:45
【问题描述】:

我想通过更改幻灯片中的每张照片来更改照片前面的照片名称。 但是使用下面的代码,输入的id根本不显示。代码如下

library(shinydashboardPlus)

ui<-    dashboardPagePlus(title="Sample",
    dashboardHeaderPlus(title="Sample"),
          
dashboardSidebar(),
dashboardBody(

fluidRow(column(width=6, 
carousel(
id = "AA",
carouselItem(
caption = "Image1",
tags$img(src = "https://cdn.sstatic.net/Sites/stackoverflow/company/Img/logos/so/so-logo.svg?v=a010291124bf", height = 400, width = 400, align="center")
),
carouselItem(
caption = "Image2",
tags$img(src = "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png", height = 400, width = 400, align="center")
))), 
column(width=6, uiOutput("Text"))
     )
)
)
server<- function(input, output, session) {
output$Text<-renderText({
Text<-input$AA
as.character(Text)
})
}
shinyApp(ui, server) ```

【问题讨论】:

    标签: r shiny shinydashboard shinyapps shiny-reactivity


    【解决方案1】:

    我确实看到他们出现了。更改字体大小和颜色更容易查看:

    library(shinydashboardPlus)
    library(shinydashboard)
    ui<-    dashboardPagePlus(title="Sample",
                              dashboardHeaderPlus(title="Sample"),
                              
                              dashboardSidebar(),
                              dashboardBody(
                                htmltools::tags$style(
                                  ".carousel-caption{
                                    font-size: 48px; 
                                    color: black;
                                  }"
                                ),
                                fluidRow(column(width=6, 
                                                carousel(
                                                  id = "AA",
                                                  carouselItem(
                                                    caption = "Image1",
                                                    tags$img(src = "https://cdn.sstatic.net/Sites/stackoverflow/company/Img/logos/so/so-logo.svg?v=a010291124bf", height = 400, width = 400, align="center")
                                                  ),
                                                  carouselItem(
                                                    caption = "Image2",
                                                    tags$img(src = "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png", height = 400, width = 400, align="center")
                                                  ))), 
                                         column(width=6, uiOutput("Text"))
                                )
                              )
    )
    server<- function(input, output, session) {
      output$Text<-renderText({
        Text<-input$AA
        as.character(Text)
      })
    }
    shinyApp(ui, server)
    

    【讨论】:

    • 谢谢。但我想通过 input$AA 显示现在显示的图像。之后打印有关该图像的一些详细信息。主要问题是 output$Text 不起作用。
    【解决方案2】:

    当您使用uiOutput 时,请在服务器端尝试renderUI。另外,要在每个图像中显示不同的文本,您需要定义renderText 并将其输出到carouselItem。试试这段代码

    library(shinydashboardPlus)
    library(shinydashboard)
    ui<-    dashboardPagePlus(title="Sample",
                              dashboardHeaderPlus(title="Sample"),
    
                              dashboardSidebar(),
                              dashboardBody(
                                      tags$head(
                                        tags$style(HTML("
                                      #AA{
                                        width:900px;
                                        height:600px;
                                        }
                                    .carousel-control{
                                      color:#FF0000;
                                    }
                                    .carousel-caption{
                                    font-size: 48px;
                                    color: red;}
                                    "))
                                      ),
                                fluidRow(column(width=6,
                                                carousel(
                                                  id = "AA",
                                                  carouselItem(
                                                    caption = "Image1",
                                                    textOutput("text1"),
                                                    tags$img(src = "https://cdn.sstatic.net/Sites/stackoverflow/company/Img/logos/so/so-logo.svg?v=a010291124bf", height = 400, width = 400, align="center")
                                                  ),
                                                  carouselItem(
                                                    caption = "Image2",
                                                    textOutput("text2"),
                                                    tags$img(src = "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png", height = 400, width = 400, align="center")
                                                  ))),
                                         column(width=6, uiOutput("Text"))
                                )
                              )
    )
    server<- function(input, output, session) {
      output$Text<-renderUI({
        #Text<-as.character(input$AA)
        tagList(
          p("I like to print something over all images", style = "color:blue")
        )
      })
      output$text1 <- renderText("Print something in image 1")
      output$text2 <- renderText("Print something in image 2")
    
    }
    shinyApp(ui, server)
    

    【讨论】:

    • 非常感谢。但我的问题是确定现在显示的是哪个图像。但是输入的id不起作用。
    • 好的。我不确定您打算如何使用该 ID 识别单个轮播项目。您可以尝试为每个图像定义单独的 textOutputs ,然后按照更新的答案所示显示它。取决于您的用例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多