R 条件带旋器

R 条件带旋器,r,shiny,R,Shiny,我正在尝试使用一个有条件的withSpinner,这样当用户选择俄亥俄州时,无论男女还是2010年,我都希望spinner出现。否则,我不希望显示微调器。有关更多信息,请参阅此图像。换句话说,我想禁用微调器,例如,将年份更改为2015年。有没有办法做到这一点 以下是我的代码的简化版本: UI ui <- fluidPage( navbarPage( collapsible = T, fluid = T, selected = "Population Projectio

我正在尝试使用一个有条件的withSpinner,这样当用户选择俄亥俄州时,无论男女还是2010年,我都希望spinner出现。否则,我不希望显示微调器。有关更多信息,请参阅此图像。换句话说,我想禁用微调器,例如,将年份更改为2015年。有没有办法做到这一点

以下是我的代码的简化版本:

UI

    ui <- fluidPage(
navbarPage(
  collapsible = T,
  fluid = T,
  selected = "Population Projections",
  windowTitle = "Scripps Interactive Data Center",
  "",

  tabPanel(("Population Projections"),

           # tags$hr(), #add a line between above command and the below one


           tags$h5 (
             strong("Current and Projected Population by County, Age Group, and Sex, 2010-2050"),
             align = 'left'
           ),

           br(),
           #a line break

           sidebarLayout(
             sidebarPanel(
               #"sidebar panel"),
               helpText("Please select your county of interest"),
               selectInput(
                 inputId = "county",
                 label = "Select County:",
                 selected = "Ohio",
                 selectize = FALSE,
                 multiple = FALSE,
                 choices = sort(unique(population$County))
               ),

               radioButtons(
                 inputId = "sex",
                 label = strong("Select Sex:"),
                 selected = "Both Sexes",
                 choices = sort(unique(population$Sex))
               ),

               sliderInput(
                 inputId = "years",
                 label = "Year",
                 min = 2010,
                 max = 2050,
                 value = 2010,
                 step = 5,
                 sep = "",
                 pre = "",
                 animate = animationOptions(
                   interval = 1000,
                   loop = F,
                   playButton = tags$button("Play", style =
                                              "background-color: #B61E2E ; color:white; margin-top: 10px; border:solid"),
                   pauseButton = tags$button("Pause", style =
                                               "background-color: #B61E2E !important; color:white; margin-top: 10px; border:solid")
                 ),
                 round = T,
                 width = "150%",
                 ticks = T
               ),


               # ### Download Button
               downloadButton("downloadData", "Download Data"),
               br(),
               br()
          #     downloadButton("downloadPlot_1", "Download Bar Graph"),

            #   br(),
             #  br(),
           #    downloadButton("downloadPlot_2", "Download Pyramid"),
             #  br(),
             #  br()

               # the number of visitors
             #  h5(textOutput("counter"))
             ),

             ######################

             mainPanel(
               tabsetPanel(
                 type = "tabs",
                 tabPanel(
                   "Plot",
                  plotOutput("bar") %>% withSpinner (color="#B61E2E"), 
                   br(),
                   br(),
                   br(),
                   #a line break

                 (column (12, align="center", tableOutput("table")))
                 ),

                 tabPanel(
                   "Pyramid",
                   plotOutput("pyramid", height=600)


                   #a line break


                 ),

                 tabPanel("Data", tableOutput("data"))
               )

                )
ui%带微调器(color=“#B61E2E”),
br(),
br(),
br(),
#断线
(列(12,align=“center”,表格输出(“表格”))
),
选项卡面板(
“金字塔”,
绘图仪输出(“金字塔”,高度=600)
#断线
),
tabPanel(“数据”,tableOutput(“数据”))
)
)
服务器

server <- function(input, output) {
  bardata <- reactive ({


    out <- population %>%
      filter (County %in% input$county,
              Year %in% input$years,
              Sex %in% input$sex)


    return(out)

  })

  blue.bold.14.text <- element_text(face = "bold", color = "black", size = 14)
  blue.bold.10.text <- element_text(face = "bold", color = "black", size = 10)
  blue.bold.12.text <- element_text(face = "bold", color = "black", size = 12)


  bardataPlot <- reactive({
    ggplot(bardata(), aes(x = Age_Group, y = Population)) + geom_bar(stat =
                                                                       "identity",
                                                                     position = "stack",
                                                                                                                           fill = "#B61E2E") +
      geom_text(
        aes(label = Percentage),
        vjust = 1,
        colour = "white", 
        position = position_dodge(width=0.9),
        fontface = "bold",
        size=5,
        angle = 90,
        hjust = 1
      ) +
      labs(
        x = "Age Groups",
        y = "Population Size",
        caption = (""),
        face = "bold"
      ) +
      theme_bw() + scale_y_continuous(labels = scales::comma) +
      theme(plot.title = element_text(
        hjust = 0.5,
        size = 15,
        colour = "Black",
        face = "bold"
      ),axis.text=(blue.bold.12.text), axis.title=blue.bold.14.text, axis.text.x = element_text(angle = -75, vjust = 0, hjust=0)) +
      ggtitle(
        paste0(
          input$sex,
          " ",
          "Population Size by 5-Year Age Groups in ",

          input$county,
          ", ", 

          input$years
        )
      )

  })

  output$bar <- renderPlot ({

    bardataPlot()

  })

server由于您的非最小示例不起作用(缺少括号?),我制作了一个新示例,展示了有条件显示微调器的方法:

library(shiny)
library(shinycssloaders)

ui <- fluidPage(
  checkboxInput("toggle", "toggle"),
  conditionalPanel(condition = "input.toggle", withSpinner(uiOutput("spinnerDummyID1"), type = 6))
)

server <- function(input, output, session) {}

shinyApp(ui, server)
库(闪亮)
图书馆(shinycssloaders)
用户界面