Pau*_*aul 7 size plot r dynamic shiny
我想要一个动态大小的情节,所有这些都应该发生在有光泽的UI中.
这是我的代码:
shinyUI{
sidebarPanel(
sliderInput("width", "Plot Width", min = 10, max = 20, value = 15),
sliderInput("height", "Plot Height", min = 10, max = 20, value = 15)
)
mainPanel(
plotOutput("plot", width="15cm", height="15cm")
)
}
Run Code Online (Sandbox Code Playgroud)
我设置"15cm"只是为了看情节.
我尝试了不同的方法从sliderInputs获取数据并将其带到plotOutput.我尝试了"input.height","输入$ heigt",但没有任何效果.
Jul*_*rre 10
您必须使用服务器端的输入,例如这里有一个解决方案:
并且宽度和高度的单位必须是有效的CSS单位,我不确定"cm"是否有效,使用"%"或"px"(或者int,它将被强制转换为带有"px"的字符串" 在末尾)
library(shiny)
runApp(list(
ui = pageWithSidebar(
headerPanel("Test"),
sidebarPanel(
sliderInput("width", "Plot Width (%)", min = 0, max = 100, value = 100),
sliderInput("height", "Plot Height (px)", min = 0, max = 400, value = 400)
),
mainPanel(
uiOutput("plot.ui")
)
),
server = function(input, output, session) {
output$plot.ui <- renderUI({
plotOutput("plot", width = paste0(input$width, "%"), height = input$height)
})
output$plot <- renderPlot({
plot(1:10)
})
}
))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3855 次 |
| 最近记录: |