我希望能够根据用户提供的.csv文件,根据对列中的值进行过滤来更新我的表.下面的代码可以正确填充我的字段,但过滤功能无法正常工作,因为它会重新更新流并取消我对值的任何 Select .


ui <- fluidPage(
  fileInput("data", "Load Data", accept = ".csv"),
  selectInput("column", "Column", character()),
  selectInput("level", "level", "select"),
  dataTableOutput("table")
)

server <- function(input, output, session){
  options(shiny.maxRequestSize=1000*1024^2)
  data <- reactive({
    req(input$data)
    read.csv(input$data$datapath)
  })
  
  observeEvent(data(), {
    updateSelectInput(session, "column", choices = names(data()))
  })
  
  observeEvent(input$column, {
    val <- data()[[input$column]]
    updateSelectInput(session, "level", choices = val,
                      label = paste("Choose level in", input$column))
  })
  
  output$table <- renderDataTable({
    req(input$level)
    filter(data(), input$level == input$level)
  })
}  

shinyApp(ui = ui, server = server)

我还try 了dplyr过滤解决方案,

     filter(input$value == input$value)

但出于同样的原因,这也不起作用.我对Shiny比较陌生,因此非常感谢您提供的任何帮助和资源.

推荐答案

也许你在找这样的东西?

使用.data代词.更多信息here.

library(shiny)
library(readr)
library(dplyr)

ui <- fluidPage(
  fileInput("data", "Load Data", accept = ".csv"),
  selectInput("column", "Column", character()),
  selectInput("level", "level", "select"),
  dataTableOutput("table")
)

server <- function(input, output, session) {
  options(shiny.maxRequestSize = 1000 * 1024^2)
  data <- reactive({
    req(input$data)
    read_csv(input$data$datapath)
  })

  observeEvent(data(), {
    updateSelectInput(session, "column", choices = names(data()))
  })

  observeEvent(input$column, {
    val <- data()[[input$column]]
    updateSelectInput(session, "level",
      choices = unique(val),
      label = paste("Choose level in", input$column)
    )
  })

  output$table <- renderDataTable({
    req(input$column)
    req(input$level)
    filter(data(), .data[[input$column]] == input$level)
  })
}

shinyApp(ui = ui, server = server)

用iris测试.用write_csv(iris, "iris.csv")创建csv

enter image description here

R相关问答推荐

使用ggcorrplot删除值,但保留不重要相关性的 colored颜色

在R中,如何在使用tibble::enFrame % % unlist转换后从收件箱中重组嵌套列表?

R:随机抽取所有可能排列的样本

在水平条形图中zoom x_轴

使用格式化程序自定义hc_tooltip以添加textColor删除了我的标记并try 将它们带回失败

使用gggplot 2在R中重新调整面板和y轴文本大小

更新合适的R mgcv::bam模型报告无效类型(关闭).'';错误

如何将在HW上运行的R中的消息(错误、警告等)作为批处理任务输出

如何求解arg必须为NULL或deSolve包的ode函数中的字符向量错误

如何在R中添加截止点到ROC曲线图?

ggplot的轴标签保存在officer中时被剪切

bslib::card_header中的shine::downloadButton,图标而不是文本

多个过滤器内的一个盒子在仪表板Quarto

在df中保留原始变量和新变量

合并DFS列表并将索引提取为新列

plotly hover文本/工具提示在shiny 中不起作用

过滤名称以特定字符串开头的文件

在数据帧列表上绘制GGPUP

通过初始的shiny 应用更新部署的shiny 应用的数据和参数,其中部署的应用程序显示为URL

使用ggplot2绘制具有边缘分布的坡度图