【发布时间】:2019-03-12 06:05:45
【问题描述】:
我有一个来自 MySQL 的表输出。我有某些过滤器,表输出依赖于这些过滤器。我将数据表作为输出,但它不是反应性的。 我在这里给出了 UI 和服务器的详细信息。你能告诉我为什么它没有反应吗?
unique_values2 <- sort(unique(opponents$opponent))
用户界面
ui <- navbarPage("Advanced",
tabPanel("Page One",
column(4,radioButtons("firstorsecond", "First Or Second",
choices = c(1:2),selected='1')),
column(4,radioButtons("tresult", "T Result",
choices = list("Won" = "Won", "Lost" = "Lost"),selected="Won")),
column(4,radioButtons("mresult", "Match Result",
choices = list("Won" = "Won", "Lost" = "Lost", "Tied"="Tied"),selected="Won")),
column(4,selectInput("opponent", "Select opponent", choices = unique_values2)),
column(4,radioButtons("position", "Position",
choices = c(1:11),inline = TRUE)),
dataTableOutput("values1")
)
)
服务器
server <- function(input, output, session) {
df<-dbGetQuery(mydb,"select
firstorsecond,position,opponent,tresult,mresult,points
from customers where cust_id=7830")
df
tablevalues1<-reactive
({
firstorsecond<-as.integer(input$firstorsecond)
position<-as.integer(input$position)
opponent<-input$opponent #String value
mresult<-input$mresult #String value
tresult<-input$toss_result #String value
df %>% filter(firstorsecond %in% firstorsecond,position %in%
position,opponent %in% opponent,mresult %in% mresult,tresult %in%
tresult)
})
output$values1 <- renderDataTable({
tablevalues1()
})
}
非常感谢您的帮助! 提前致谢!
【问题讨论】:
-
问题可能是变量名冲突。您可能应该针对您的条件尝试类似
mresult %in% input$mresult的方法以避免歧义。现在filter函数可能使用运算符的 LHS 和 RHS 表列。 -
道歉。我可能应该更清楚 - 我的数据表对我的 input$ 变量没有反应。数据看起来像这样 - ibb.co/1zDBLXN .
-
我尝试按照您的建议更改变量名称,Rohit。但即使是数据表(没有对过滤器的反应)现在也没有打印出来,而不是以前。
-
您能否发布您的输入数据框以及您尝试使用它的结果的代码?这将有助于我进行实验。
-
我已将您的新代码添加为对您帖子的编辑。不建议在 cmets 中发布多个代码表达式。请查看
dput函数,了解如何以首选格式发布数据