闪亮:多个conditionalPanels,相同的条件

时间:2015-12-28 23:09:08

标签: r shiny

我在包含多个使用相同条件的conditionalPanel的ui中使用textOutput时遇到问题。在下面的示例中,textOutput(“sampleReturn2”)无法正常工作(即,未注册“school”输入)。有什么我可以做的重组,以便这些工作正常吗?

PS我是今天的堆栈溢出的新手 - 我希望下面的例子提供了足够的信息。提前谢谢!

sampleFunction      <-      function(report, school)
{
paste(report, school, "TEST", sep = '')
}

aa <- shinyUI(
fluidPage(
    fluidRow(
        column(1),
        column(2, h4(strong('Sample Tool')), br(),
            selectInput("report",
            label = 'Input 1',
            choices = c(
                ' ',
                'AA' = '1',
                'BB' = '2'),
            selected = ' ',
            multiple = FALSE
            )),
        column(4, br(), br(), br(),
            conditionalPanel(
            condition = "input.report == 1",
            selectInput("school", width = '100%',
                label = 'Input 2a',
                choices = c(' ' , '11', '22', '33', '44'),
                selected = ' ',
                multiple = FALSE
            )),
            conditionalPanel(
            condition = "input.report == 2",
            selectInput("school", width = '100%',
                label = 'Input 2b',
                choices = c(' ', '55', '66', '77', '88'),
                selected = ' ',
                multiple = FALSE
            )))
    ), 
    hr(),
    conditionalPanel(
    condition = "input.report == 1",
    fluidRow(
        column(6,
            fluidRow(
                column(6, h4(strong('Actual SPR Scores'), align = 'left'))
                ),
            "Sample Return 1", textOutput("sampleReturn1")
            ),
        column(6,
            fluidRow(
                column(6, h4(strong('Adjusted SPR Scores'), align = 'left'))
                ),
            "ADJUSTED AA REPORT SCORES"
            )),
        hr(),
        tabsetPanel(type = 'tabs',
            tabPanel("CATEGORY A", 
                column(6, "CATEGORY A ACTUAL SCORES"),
                column(6, "CATEGORY A ADJUSTED SCORES")
                ),
            tabPanel("CATEGORY B", 
                column(6, "CATEGORY B ACTUAL SCORES"),
                column(6, "CATEGORY B ADJUSTED SCORES")
                ),
            tabPanel("CATEGORY C",
                column(6, "CATEGORY C ACTUAL SCORES"),
                column(6, "CATEGORY C ADJUSTED SCORES")
                ),
            tabPanel("CATEGORY D", 
                column(6, "CATEGORY D ACTUAL SCORES"),
                column(6, "CATEGORY D ADJUSTED SCORES")
                )
            )
        ),
    conditionalPanel(
    condition = "input.report == 2",
    fluidRow(
        column(6,
            fluidRow(
                column(6, h4(strong('Actual SPR Scores'), align = 'left'))
                ),
            "Sample Return 2", textOutput("sampleReturn2")
            ),
        column(6,
            fluidRow(
                column(6, h4(strong('Adjusted SPR Scores'), align = 'left'))
                ),
            "ADJUSTED BB REPORT SCORES"
            )),
        hr(),
        tabsetPanel(type = 'tabs',
            tabPanel("CATEGORY A", 
                column(6, "CATEGORY A ACTUAL SCORES"),
                column(6, "CATEGORY A ADJUSTED SCORES")
                ),
            tabPanel("CATEGORY B", 
                column(6, "CATEGORY B ACTUAL SCORES"),
                column(6, "CATEGORY B ADJUSTED SCORES")
                ),
            tabPanel("CATEGORY C",
                column(6, "CATEGORY C ACTUAL SCORES"),
                column(6, "CATEGORY C ADJUSTED SCORES")
                )
            )
        )
    )
)

bb <- shinyServer(function(input, output){
output$sampleReturn1        <-      renderText({sampleFunction(input$report, input$school)})
output$sampleReturn2        <-      renderText({sampleFunction(input$report, input$school)})        
})

runApp(list(ui = aa, server = bb))

0 个答案:

没有答案