0

我的代码中有一个复选框和一个表格。我想要的是当用户选中某个框时,会生成具有相应名称的新列。

理想案例示例:

在此处输入图像描述

但是,这就是我的代码:

在此处输入图像描述

这是我的代码:

lineGraphUI <- function(id) {
  ns <- NS(id)
  tags$div(
    checkboxGroupInput(ns("variable"), "Variables to show:",
                       c("black" = "black",
                         "white" = "white",
                         "asian" = "asian")),
    tableOutput(ns("datatbr"))
  )
}

lineGraph <- function(input, output, session) {
  da <- read.csv(file = "RaceByYearTemplet.csv", header = TRUE)  

  output$datatbr <- renderTable({
    da[c("year",input$variable), drop = FALSE]
  }, rownames = TRUE)
}

navBlockUI <- function(id) {
  ns <- NS(id)
  tags$div(
    tags$div(class = "tabPanel-plotBlock",
             tabsetPanel(type = "tabs",
                         tabPanel("Graph", lineGraphUI(ns("line"))),
                         tabPanel("Line", tablePlotUI(ns("table")))
             )
    ) 
  )
}

navBlock <- function(input, output, session) {
  callModule(lineGraph, "line")

  callModule(tablePlot, "table")
}

我认为当复选框被选中时,问题可能无法更新闪亮的模块?因为我试图将相同的代码直接放在 app.R 中并且它工作得很好(如上面的“理想案例示例”图像所示)。

4

1 回答 1

0

这像这样工作:

lineGraphUI <- function(id) {
  ns <- NS(id)
  tags$div(
    checkboxGroupInput(ns("variable"), "Variables to show:",
                       c("black" = "black",
                         "white" = "white",
                         "asian" = "asian")),
    tableOutput(ns("datatbr"))
  )
}

lineGraph <- function(input, output, session) {
  da <- iris[1:5,]
  names(da) <- c("black", "white", "asian", "abcd", "year")

  output$datatbr <- renderTable({
    da[, c("year",input$variable), drop = FALSE]
  }, rownames = TRUE)
}

navBlockUI <- function(id) {
  ns <- NS(id)
  tags$div(
    tags$div(class = "tabPanel-plotBlock",
             tabsetPanel(type = "tabs",
                         tabPanel("Graph", lineGraphUI(ns("line")))
             )
    ) 
  )
}

ui <- fluidPage(
  navBlockUI("xxx")
)
navBlock <- function(input, output, session) {
  callModule(lineGraph, "xxx-line")
}

shinyApp(ui, navBlock)
于 2019-06-09T08:05:20.163 回答