是否有R函数为Renderdatatable应用过滤器

时间:2019-07-10 04:56:11

标签: r shiny dt

是否有R函数在renderDatatable下应用过滤器。我已经将表格转换为矩阵形式,但是仍然出现错误。如果我应用renderPrint和verbatimTextOutput

,我将获得输出。
sample1 <- 1:3
library(shiny)
library(DT)
iris$New <- ifelse(iris$Sepal.Width>2.5,"greater than 2.5","Not Greater than 
2.5")
ui <- fluidPage(
sidebarLayout(
sidebarPanel(selectInput("x","Operations",choices = 
                           c("summary","stem","typeof","mode","birth"),
                         multiple=FALSE,selectize = TRUE)),
mainPanel(h6("Here it is"),
          dataTableOutput("message"),
          uiOutput("Species"),
          uiOutput("all"),
          uiOutput("New")
)
)
)
server <- function(input, output, session) 
{
r1 <- reactive({
if(input$x == "summary")
  { 
  req(input$Species)
  if(input$Species == "all")
  {
    table(iris$Species,iris$New[iris$New == input$New])
  } else {
    table(iris$Species,iris$New[iris$Species == input$Species & iris$New == 
  input$New])
  }}
  })
  output$message <- renderDataTable({r1()})
  output$Species <- renderUI({
  selectInput("Species", "species", 
            choices = c("all",as.character(unique(iris$Species))), multiple 
  = FALSE)
  })
  output$New <- renderUI({
  selectInput("New", "new", 
            choices = as.character(unique(iris$New)), multiple = FALSE)
  })
  }
  shinyApp(ui, server)

我可以摆脱这个错误吗?

0 个答案:

没有答案