通过选择单选按钮来渲染信息框

时间:2018-12-27 10:16:38

标签: r shiny

在选择单选按钮时,我无法构建将呈现“ infoBox”的代码。

代码如下:

library(shiny)
library(shinydashboard)
ui <- shinyUI(
fluidPage(h5("D"),
mainPanel(
tabsetPanel(type = "tab",
tabPanel(
fluidRow(
radioButtons("rad", "Select box",
               c("1" = "norm",
                 "2" = "unif")

norm <- box(h3("Super")
infoBox("10", "ab", width = 6)
infoBox("11", "bc", width = 6)
),
unif <-box(h3("Duper")
infoBox("20", "cd", width = 6)
infoBox("21", "de", width = 6)
)))))))

infoBoxOutput("loc")

server <- shinySever(function(input, output){
output$loc <- {(
renderinfoBox(input$rad)
)}
})

shinyApp(ui, server)

我遇到错误: if(内联){时出错:参数不能解释为逻辑 sample respresent

sample representation

1 个答案:

答案 0 :(得分:0)

这是一个可行的示例。

library(shiny)
library(shinydashboard)
ui <- shinyUI(fluidPage(h5("D"),
                        mainPanel(
                          tabsetPanel(type = "tab",
                                      tabPanel("T1"),
                                      tabPanel(
                                        "T2",
                                        fluidRow(radioButtons(
                                          "rad",
                                          "Select box",
                                          c("1" = "norm", "2" = "unif")
                                        ),
                                        infoBoxOutput("loc"))
                                      ))
                        )))



server <- function(input, output) {
  output$loc <- renderInfoBox({
    if (input$rad == "norm") {
      box(h3("Super"),
          infoBox("10", "ab", width = 6),
          infoBox("11", "bc", width = 6))
    } else{
      if (input$rad == "unif") {
        box(h3("Duper"),
            infoBox("20", "cd", width = 6),
            infoBox("21", "de", width = 6))
      }
    }
  })
}

shinyApp(ui, server)
相关问题