我正在尝试在闪亮的应用程序中创建和呈现交互式formattable表。
这是一个示例数据框:
tcharts <- data.frame(pgm = c(1,2,3,4,5,6,7,8),horse = c("Cigar","Funny Cide","Animal Kingdom","blame","Zenyatta","New Years Day","Northern Dancer","Beautiful Pleasure"),groundloss = c(55,70,85,42,90,45,53,50),distanceRun = c(5050,5070,5085,5045,5090,5053,5050),ttl = c(50,fps = c(52.3,51.8,51.9,52.0,53.6,52.9,53.7,53.1),finishTime = c(52.3,finish = c(4,1,BL = c(0,9,rnum = c(1,1),sixteenth = c(330,330,330)
)
工作版本
当list()为空(使用数据帧中的所有变量)时,此版本的代码将按预期生成表。
library(shiny)
library(formattable)
inputPanel(
selectInput("rnum",label = "Race Number:",choices = c(1,8,9),selected = 1),sliderInput("poc",label = "Point of Call:",min = 330,max = 5280,value = 330,step = 330)
)
cdat <- reactive({
tcharts %>% filter(rnum %in% input$rnum) %>%
filter(Sixteenth %in% input$poc)
})
renderFormattable({
formattable(cdat(),list(
))
})
错误版本:
在此版本中,我收到一个错误:找不到对象pgm
library(shiny)
library(formattable)
inputPanel(
selectInput("rnum",list(
pgm,Horse
))
})
该错误消息使我相信我没有正确指定变量,但是我不确定该怎么做。我查看了几个可格式化的/有光泽的SO问题和答案,但没有提出正确的语法。