簡體   English   中英

反應區大小,有光澤

[英]Reactive plot size, 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)

暫無
暫無

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

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