簡體   English   中英

checkboxInput和conditionalPanel閃亮

[英]checkboxInput and conditionalPanel in shiny

選擇s1時,僅顯示一個sidebarPanel和mainPanel,結果alpha為0.05,功效為0.8。 選擇s2時,僅顯示一個sidebarPanel和mainPanel,結果alpha為0.1,功效為0.9。

這是我的ui.R和server.R。

以下是我的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")
                                         )
                                       )
                                     )
                    )
          )
    ))))

以下是我的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)

非常感謝你。

這應該為您工作。 您將需要稍微修改服務器代碼以處理不同的ID。 各種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")
                            )
                          )
                        )
               )
    ))))

我最近遇到這個問題就來了,而研究一個類似的一個

這不是上述答案的替代方案,但我認為有必要指出,因為問題的標題是shick中的checkboxInput和conditionalPanel

至少對checkboxInput條件的簡單回答如下:

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

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

顯然,仍然存在唯一ID的問題,並且在上述情況下radioButtons()在這種情況下更合適。

暫無
暫無

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

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