简体   繁体   English

checkboxInput和conditionalPanel闪亮

[英]checkboxInput and conditionalPanel in shiny

When choose s1, only show one sidebarPanel and mainPanel,the results alpha was 0.05 and power was 0.8. 选择s1时,仅显示一个sidebarPanel和mainPanel,结果alpha为0.05,功效为0.8。 When choose s2, only show one sidebarPanel and mainPanel,the results alpha was 0.1 and power was 0.9. 选择s2时,仅显示一个sidebarPanel和mainPanel,结果alpha为0.1,功效为0.9。

This is my ui.R and server.R. 这是我的ui.R和server.R。

Below is the code for my ui.R file: 以下是我的ui.R文件的代码:

library(shiny)
ui <- shinyUI(fluidPage(
  titlePanel("aaaaaaaaaaaaaaaa"),
  tabsetPanel(
    navbarMenu("Means",
           tabPanel("One Mean"),
           tabPanel("Two Means",
                    wellPanel(
                      checkboxInput(inputId = "s1", label = "S1", value = FALSE),
                      checkboxInput(inputId = "s2", label = "S2", value = FALSE)
                    ),
                    conditionalPanel(condition="input.s1==true",
                      sidebarPanel(
                        p(strong("Error Rates")),
                        numericInput("alpha", label="Alpha", min=0, max=1,value=0.05),
                        numericInput("power", "Power", 0.8),
                        actionButton("submit","Submit")
                      ),
                      mainPanel(
                        tabsetPanel(
                          tabPanel("Main",
                                   tableOutput("Table"),
                                   uiOutput("Text")
                          )
                        )
                      )
                    ),
                    conditionalPanel(condition="input.s2==true",
                                     sidebarPanel(
                                       p(strong("Error Rates")),
                                       numericInput("alpha", label="Alpha", min=0, max=1,value=0.1),
                                       numericInput("power", "Power", 0.9),
                                       actionButton("submit","Submit")
                                     ),
                                     mainPanel(
                                       tabsetPanel(
                                         tabPanel("Main",
                                                  tableOutput("Table"),
                                                  textOutput("Text")
                                         )
                                       )
                                     )
                    )
          )
    ))))

Below is the code for my server.R file: 以下是我的server.R文件的代码:

server <- shinyServer(function(input, output) {
output$Table <- renderTable({
if(input$submit > 0) { 
  output<-data.frame(input$alpha,input$power)
  output
}
})

output$Text<-renderText({
if(input$submit > 0) {
  paste("alpha and power are",input$alpha,"and",input$power)
}
})
})

shinyApp(ui = ui, server = server)

Thank you very much. 非常感谢你。

This should work for you. 这应该为您工作。 You would need to slightly modify the server code to handle the different IDs. 您将需要稍微修改服务器代码以处理不同的ID。 You cannot have the same id for the various UI elements. 各种UI元素不能具有相同的ID。

ui <- shinyUI(fluidPage(
  titlePanel("aaaaaaaaaaaaaaaa"),
  tabsetPanel(
    navbarMenu("Means",
               tabPanel("One Mean"),
               tabPanel("Two Means",
                        wellPanel(
                          radioButtons(inputId = "buttons", "Selections", c("S1", "S2"), selected = "S1", inline = TRUE)
                        ),
                        sidebarPanel(
                          conditionalPanel(condition = "input.buttons == 'S1'",
                                           p(strong("Error Rates")),
                                           numericInput("alpha", label="Alpha", min=0, max=1,value=0.05),
                                           numericInput("power", "Power", 0.8),
                                           actionButton("submit","Submit")
                                           ),
                          conditionalPanel(condition = "input.buttons == 'S2'",
                                           p(strong("Error Rates")),
                                           numericInput("alpha1", label="Alpha", min=0, max=1,value=0.1),
                                           numericInput("power1", "Power", 0.9),
                                           actionButton("submit1","Submit")
                                           )
                        ),
                        mainPanel(
                          tabsetPanel(
                            tabPanel("Main",
                                     tableOutput("Table"),
                                     textOutput("Text")
                            )
                          )
                        )
               )
    ))))

I came across this question recently while researching a similar one . 我最近遇到这个问题就来了,而研究一个类似的一个

This is not an alternative to the above answer but I thought it necessary to point out as the title of the question is checkboxInput and conditionalPanel in shiny . 这不是上述答案的替代方案,但我认为有必要指出,因为问题的标题是shick中的checkboxInput和conditionalPanel

The simple answer to the the checkboxInput condition at least is as below: 至少对checkboxInput条件的简单回答如下:

conditionalPanel(condition="input.s1==1",

and

conditionalPanel(condition="input.s2==1",

Obviously there is still the issue of unique IDs and the fact that radioButtons() is more appropriate in this context which are dealt with above. 显然,仍然存在唯一ID的问题,并且在上述情况下radioButtons()在这种情况下更合适。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM