checkboxGroupInput的长度

时间:2016-10-14 12:56:01

标签: r shiny shinydashboard

我是R的新手,我有一点问题。

我有一个名为BI14的巨大数据框(250000行/ 190列),为了更快地显示数据,如果只选中一个框,我想创建一个新的数据框。

示例:我检查了城镇2复选框,因此,当我单击数据选项卡时,程序将从B14创建一个名为BI14_02的数据框,并显示该数据框的数据而不是大数据帧。另一种情况:如果我检查第三个县,程序将创建一个名为BI14_East的数据框。 如果我在县或城镇选项卡中选中多个框,或者如果我选择国家/地区选项卡,将使用巨大的数据框,并且当我单击数据选项卡时将显示数据。如果我可以为每个复选框创建一个新的数据框,但我认为使用" NROW"在几个数据框架中同时指导一个像我这样的新手。

所以,我认为最好使用" length"确定是否选中了一个或多个复选框的说明,但我需要你的帮助。

这是Ui.R代码:

library(shiny)
library(DT)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "TEST",titleWidth = 500
                  ), # dashboardHeader close

  dashboardSidebar(## Sidebar content
    sidebarMenu(
    menuItem("Level", tabName = "level", icon = icon("arrow-down")),
    menuSubItem("Country",icon = icon("globe"), tabName = "country"),
    menuSubItem("County",icon = icon("circle-o"), tabName = "county"),
    menuSubItem("Town",icon = icon("spinner"), tabName = "town"),
    menuItem("datas", tabName = "datas", icon = icon("list-alt")),
    menuItem("Maps", tabName = "maps", icon = icon("th"))
           ) # sidebarMenu close
              ), # f. de dashboardSidebar

  # Body content
  dashboardBody(
    tabItems(# Country tab content
      tabItem(tabName = "country",
        fluidRow(
            box(title = "Click on datas tab", width = 9, 
                 background = "olive")
                ) # fluidRow close
            ), # tabItem close

  # County tab content
  tabItem(tabName = "county",
        fluidRow(
          box(title = "Counties", width = 3, solidHeader = TRUE,
              status = "primary",
              checkboxGroupInput("dynamic_counties", label = "",
                          choices = list("First county"  = "North",
                                         "Second county" = "South",
                                         "Third county" = "East"))
              ) # box close
                ) # fluidRow close
        ), # tabItem close

  # Town tab content
  tabItem(tabName = "town",
          #h4("Check one or more box(es)",              
          checkboxGroupInput(
              "dynamic", label = h4("Check one or more box(es)"),
            choices = list("01. Town 1"  =     "01", "02. Town 2" = "02",
                           "03. Town 3" = "03", "04. Town 4" = "04",
                           "05. Town 5" = "05", "06. Town 6" = "06",
                           "07. Town 7" = "07", "08. Town 8" = "08",
                           "09. Town 9" = "09", "10. Town 10" = "10",
                           "11. Town 11" = "11", "12. Town 12" = "12"))

        ), # tabItem close

  tabItem(tabName = "datas",
          fluidRow(
            box(title = "General datas", solidHeader = TRUE,
                         status = "primary",
                DT::dataTableOutput("df"))
                  ) # fluidRow close
          ) # tabItem close
     ) # tabItems close
  ) # dashboardBody close
) # dashboardPage close

在Server.R中,我有这个,但是有错误而我无法解决它:

observe({town<-renderText({input$dynamic})
 if (length(input$dynamic) = 1){paste("BI14_",town)<-subset(BI14,PC %in%
 input$dynamic)}})

我认为这很容易,但我正在学习R ...

非常感谢您的帮助。

祝你有个美好的一天。

0 个答案:

没有答案