簡體   English   中英

如何通過更改閃亮的幻燈片來更改文本

[英]how to change the text by change the slides in shiny

我想通過更改幻燈片中的每張照片來更改照片前面的照片名稱。 但是使用以下代碼,根本不顯示輸入的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) ```

我確實看到他們出現了。 如果更改字體大小和顏色,則更容易查看:

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)

在此處輸入圖片說明 在此處輸入圖片說明

當您使用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)

輸出

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM