按下按钮后表格未呈现

时间:2019-11-25 22:30:28

标签: shiny

我是RShiny的新手。我试图在按下按钮时呈现表格。我要修改的数据是:

data.csi.m <-
1 18617736  33/47      N/A    N/A
2 18617736  33/47      N/A    N/A
3  1699471    N/A      N/A    N/A
4  1699471    N/A      N/A    N/A
5  1699471    N/A      N/A    N/A
6  1699471    N/A      N/A    N/A
7  1584923    N/A      N/A    N/A
8  1584923    N/A      N/A    N/A
9 28453930    N/A      N/A    N/A
10 28453930    N/A      N/A    N/A
11 22134919    N/A      N/A    N/A
12 22134919    N/A      N/A    N/A
13 22134919    N/A      N/A    N/A
14 22134919    N/A      N/A    N/A
15 22134919    N/A      N/A    N/A
16 22134919    N/A      N/A    N/A
17 27255810  17/17      N/A    N/A
18 27255810  16/19      N/A    N/A
19 27255810  19/19      N/A    N/A
20 27255810  17/17      N/A    N/A

这是我通过RStudio构建的应用代码:


library(shiny)
library(dbplyr)
library(dplyr)
library(DBI)
library(ggplot2)
library(RMySQL)
library(DT)

RV <- reactiveValues(data = data.csi.m)

ui <- fluidPage(
  headerPanel('Search Filter'),
  sidebarPanel(
    selectInput("ageddmenu", "Age:",
                c(">" = ">",
                  "<" = "<",
                  "=" = "=",
                  ">=" = ">=",
                  "<=" = "<=",
                  "!=" = "!=")),
    sliderInput("ageslider", "Age:",
                min = 50, max = 100, value = 60
    ),
    checkboxGroupInput("genderCheckBox", "Sex:",
                       c("M" = "M",
                         "F" = "F")),
    actionButton("filterButton", "Filter", icon("filter"))
  ),
  mainPanel(
    h2("Clinical Subject Information"),
    #DT::datatable(data.csi.m,class = 'cell-border stripe', elementId="csi"),
    DT::dataTableOutput("csi"),
    h2("Summary Plot"),
    plotOutput('plot1')

  )
)

server = (function(input, output) {


  observeEvent(input$filterButton, {
    temp <-  RV$data[1:3, 1:10]
    RV$data <- temp
    print(RV$data)

  })
  output$csi <- renderTable(RV$data)
})

shinyApp(ui = ui, server = server)



但是,data.frame没有呈现。我已搜索寻求任何帮助,但建议没有奏效。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

它是renderDataTable,而不是renderTable。有时总是有助于重新审视代码!

data.csi.m <- data.frame(col1 = c(18617736, 18617736, 1699471, 1699471), col2 = c("33/47", "33/47", "N/A", "N/A"), col3 = c("N/A", "N/A", "N/A", "N/A"), stringsAsFactors = FALSE)

library(shiny)
library(dplyr)
library(DBI)
library(ggplot2)
library(DT)

RV <- reactiveValues(data = data.csi.m)

ui <- fluidPage(
  headerPanel('Search Filter'),
  sidebarPanel(
    selectInput("ageddmenu", "Age:",
                c(">" = ">",
                  "<" = "<",
                  "=" = "=",
                  ">=" = ">=",
                  "<=" = "<=",
                  "!=" = "!=")),
    sliderInput("ageslider", "Age:",
                min = 50, max = 100, value = 60
    ),
    checkboxGroupInput("genderCheckBox", "Sex:",
                       c("M" = "M",
                         "F" = "F")),
    actionButton("filterButton", "Filter", icon("filter"))
  ),
  mainPanel(
    h2("Clinical Subject Information"),
    DT::dataTableOutput("csi"),
    h2("Summary Plot"),
    plotOutput('plot1')

  )
)

server = (function(input, output) {


  observeEvent(input$filterButton, {
    temp <-  RV$data[1:3, 1:10]
    RV$data <- temp
    print(RV$data)

  })
  output$csi <- DT::renderDataTable(RV$data)
})

shinyApp(ui = ui, server = server)