[英]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.