如何通过更改闪亮的幻灯片来更改文本
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/Whosebug/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/Whosebug/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/Whosebug/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。代码如下
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/Whosebug/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/Whosebug/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/Whosebug/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)