2017-03-20 1 views
0

1つのrenderPlot呼び出し(サーバー内)と対応する1つのplotOutput呼び出し(ui内)を含むRShinyアプリケーションを構築しています。しかし、renderPlotコード内には、2つの異なるプロットを切り替えるUIからのトグルがあります。私はプロットが異なる座標を持つことを望みます。以下は私の質問の側面を強調するために、一般的なプロットを使用して再現性RShinyアプリです:RShinyでは、同じrenderPlot()内の別のプロットのプロットの幅/高さを変更します。

selector = c("one", "two") 
names(selector) = c("one", "two") 

plot.width = 600 
plot.height = 600 

ui <- fluidPage(
       fluidRow(
        # Organizes the title of the whole shiny app 
        # ========================================== 
        column(width = 12, align = 'center', 
         h2('NBA Shot Chart and Movement Tracking Application')) 
       ), 

       fluidRow(
        # This coordinates the location of the LHS widgets 
        # ================================================     
        column(width = 4, align = 'center', 
          selectInput(inputId = 'shooter.input', label = 'Select Shooter:', multiple = FALSE, 
             choices = selector, selected = 'one')), 

        column(width = 8, align = 'left', 
         plotOutput('shot.chart', width = plot.width, height = plot.height) 
       ) 
       ) 
) 

server <- shinyServer(function(input, output) { 

    # renderPlot for the charts (shot charts and movement charts) 
    output$shot.chart <- renderPlot({ 

    if(input$shooter.input == "one") { 
     plot(c(1,2,3,4,5), c(6,7,8,9,10)) 
    } 
    else { 
     plot(c(1,2,3,4,5), c(1,1,1,1,1)) 
    } 
    }) 
}) 

shinyApp(ui = ui, server = server) 

さて、私の質問は、UIにplotOutputに設定plot.widthとplot.heightパラメータに関係しています。これらのパラメータを2つのプロットごとに変更します。 selectInputが== "1"に設定されている場合、パラメータを600と600に設定し、selectInputが== "2"に設定されている場合は、パラメータを600と800にします。

前にこの問題は、それを処理する方法を知っていますか? ありがとう!ここで

答えて

1

は、ソリューションです:

library(shiny) 

selector = c("one", "two") 
names(selector) = c("one", "two") 


ui <- fluidPage(
    fluidRow(
    # Organizes the title of the whole shiny app 
    # ========================================== 
    column(width = 12, align = 'center', 
      h2('NBA Shot Chart and Movement Tracking Application')) 
), 

    fluidRow(
    # This coordinates the location of the LHS widgets 
    # ================================================     
    column(width = 4, align = 'center', 
      selectInput(inputId = 'shooter.input', label = 'Select Shooter:', multiple = FALSE, 
         choices = selector, selected = 'one')), 

    column(width = 8, align = 'left', 
      uiOutput('shot.chart_ui') 
    ) 
) 
) 

server <- shinyServer(function(input, output) { 


    output$shot.chart_ui <- renderUI({ 
    if(input$shooter.input == "one") { 
     plot.width = 600 
     plot.height = 600 
    }else{ 
     plot.width = 600 
     plot.height = 800 
    } 
    plotOutput('shot.chart', width = plot.width, height = plot.height) 

    }) 
    # renderPlot for the charts (shot charts and movement charts) 
    output$shot.chart <- renderPlot({ 

    if(input$shooter.input == "one") { 
     plot(c(1,2,3,4,5), c(6,7,8,9,10)) 
    } 
    else { 
     plot(c(1,2,3,4,5), c(1,1,1,1,1)) 
    } 
    }) 
}) 

shinyApp(ui = ui, server = server) 

私はserverplotOutputを移動していると、さらに私は、反応性コンテキストにplot.widthplot.heightを入れています。

関連する問題