如何使 Shiny 应用程序中的图像宽度动态化?
How can I make the width of an image in a Shiny app dynamic?
我正在编写一个应用程序,我希望侧边栏面板中的图像比我放入其中的图像大一点。随着 window 变小或变大,侧边栏也会变小或变大,但图像保持静止。我该如何解决这个问题?有没有办法获取侧边栏的长度或者有更好的渲染图像的方法?
ui.R
library(shiny)
shinyUI(bootstrapPage(
# Application title
titlePanel("Sidebar Image App"),
sidebarPanel(
imageOutput("image", height = "auto")
)
))
server.R
library(shiny)
shinyServer(function(input, output, session) {
output$image <- renderImage({
return(list(
src = "one.png",
contentType = "image/png",
height = 185,
alt = "Face"
))
})
})
您可以使用 css 标签设置图像样式,如下所示:
shinyUI(bootstrapPage(
titlePanel("Sidebar Image App"),
tags$head(tags$style(
type="text/css",
"#image img {max-width: 100%; width: 100%; height: auto}"
)),
sidebarPanel(
imageOutput("image")
)
)),
其中cssid选择器(这里#image
)应该对应imageOutput
.
的outputId
我正在编写一个应用程序,我希望侧边栏面板中的图像比我放入其中的图像大一点。随着 window 变小或变大,侧边栏也会变小或变大,但图像保持静止。我该如何解决这个问题?有没有办法获取侧边栏的长度或者有更好的渲染图像的方法?
ui.R
library(shiny)
shinyUI(bootstrapPage(
# Application title
titlePanel("Sidebar Image App"),
sidebarPanel(
imageOutput("image", height = "auto")
)
))
server.R
library(shiny)
shinyServer(function(input, output, session) {
output$image <- renderImage({
return(list(
src = "one.png",
contentType = "image/png",
height = 185,
alt = "Face"
))
})
})
您可以使用 css 标签设置图像样式,如下所示:
shinyUI(bootstrapPage(
titlePanel("Sidebar Image App"),
tags$head(tags$style(
type="text/css",
"#image img {max-width: 100%; width: 100%; height: auto}"
)),
sidebarPanel(
imageOutput("image")
)
)),
其中cssid选择器(这里#image
)应该对应imageOutput
.
outputId