r - 生成反应输入表
问题描述
我有一个反应式闪亮,它连接到 MySQL 并根据用户的输入呈现数据表。在表中mytable
,
A 列的值 -赢或输
B 列的值 -赢或输或平局
C 列的值 - 1 到 9
D 列的值 - 0 到 150
E 列的值 - 1 或 2
这 4 个值是根据用户输入选择的。该表mytable
还有其他列,例如 E 和 F,它们不依赖于用户输入。
ui <- fluidPage(fluidRow(
column(4,radioButtons("firstorsecond", "First or Second",
choices = c(1: 2),selected='1')),
column(4,radioButtons("anotherselection", "Choose won or lost",
choices = list("Won" = 1, "Lost" = 2),selected='1')),
column(4,radioButtons("result", "Match Result",
choices = list("Won" = 1, "Lost" = 2, "Tied"=3),selected='1')),
column(4,checkboxGroupInput("pos", "Position",
choices = c(1:9),inline = TRUE)),
column(4,sliderInput("range", "Score Range", min = 0,
max = 150,value = c(25,75))
))
)
server <- function(input, output)
{
rs=dbSendQuery(mydb,"select A,B,C,D,E,F from mytable where name='abcd'")
adv_ana=fetch(rs,n=-1)
dataInput<-reactive({
**code goes here**
})
}
在
dataInput<-reactive({})
中,帮我弄清楚如何获取输入值并显示包含所有列的表格。
提前致谢。
解决方案
您可以dplyr::filter
根据您的条件过滤行(未经测试,因为我没有您的数据):
datainput <- reactive{(
your_table %>%
dplyr::filter(A == input$firstorsecond,
B == input$anotherselection,
C == input$result,
D == input$pos)
})
您可能已经适应了您的实际输入,因为我计算了 5 个输入,而在您的描述中您只提到了 4 列。
推荐阅读
- excel - 处理每个循环中包含一个元素的数组
- amazon-web-services - 我可以自动强制执行 S3 服务器访问日志记录的最佳方式是什么?
- reactjs - React/Typescript:对象作为 React 子项无效
- javascript - 带有 dotenv 和 TypeScript 的环境变量
- javascript - Dialogflow:如何在环聊中接收图片?(Javascript)
- java - 检查 jdom2 中 Java 中给定 xml 的属性是否存在
- ruby-on-rails - 如何在 Rails 中使用 JSONB 和 Ruby Geocoder?
- python - 无法从 powershell 访问 python
- javascript - 使用 AJAX 渲染 HTML
- python - Gurobi 表达式如何在 Python 上工作?