gpt4 book ai didi

react 性地 block 大小,有光泽

转载 作者:行者123 更新时间:2023-12-05 01:02:35 24 4
gpt4 key购买 nike

是否有可能以某种方式在 Shiny 中具有反应性绘图大小?

这是一个小例子,我希望它如何工作。尽管响应式表达式不在输出中,但它会给出错误。

ui.R,您可以在其中选择宽度和两个绘图输出:

shinyUI(pageWithSidebar(
headerPanel("Title"),
sidebarPanel(
selectInput("width", "Choose width:",
choices = c("200", "400"))
),

mainPanel(
plotOutput(outputId = "main_plot", width = "100%"),
plotOutput(outputId = "main_plot2", width = "100%")
)
))

server.R,其中第二个绘图应具有输入宽度:

shinyServer(function(input, output) { 
x <- 1:10
y <- x^2
width <- reactive({
switch(input$direction,
'200' = 200,
'400' = 400)
})
output$main_plot <- renderPlot({
plot(x, y)}, height = 200, width = 400)
output$main_plot2 <- renderPlot({
plot(x, y) }, height = 200, width = width() )
})

最佳答案

你的关闭,试试这个:

ui <- shinyUI(pageWithSidebar(
headerPanel("Title"),
sidebarPanel(
selectInput("direction", "Choose width:",
choices = c("200", "400"))
),

mainPanel(
plotOutput(outputId = "main_plot", width = "100%"),
plotOutput(outputId = "main_plot2", width = "100%")
)
))

server <- shinyServer(function(input, output) {
x <- 1:10
y <- x^2

output$main_plot <- renderPlot({
plot(x, y)}, height = 200, width = 400)

observe({
output$main_plot2 <- renderPlot({
plot(x, y) }, height = 200, width = as.numeric(input$direction))
})

})

shinyApp(ui=ui,server=server)

关于 react 性地 block 大小,有光泽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33391673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com