我正在尝试在R中使用bscols / crosstalk / DT创建两个单独的sharedData数据集,以创建一个单独的R markdown文件中的交互。
就Google而言,我似乎已正确设置了所有内容,并且未收到任何错误消息。但是,当我打开HTML并单击过滤器时,什么也没发生,所以一定有问题...
下面的代码-当我意识到过滤器不起作用时,我正在研究对象的放置,所以的确,它们有些不同(如果您像我这样的OCD!)>
## shipper version ##
## set up data set ##
temp_shipper <- rate_lvl_ship %>%
subset(
select = c(
'OrigName',
'OrigCity',
'OrigState',
'RateCode',
'RateDesc',
'Score',
'Discrepancies',
'DiscPer',
'RateCat'
)
)
temp_shipper <- temp_shipper[order(-temp_shipper$Score),]
temp_shipper$DiscPer <- paste(
formatC(
temp_shipper$DiscPer*100,
digits = 2,
format = 'f'
) %>% as.character(),
'%'
)
temp_shipper$Discrepancies <- formatC(
temp_shipper$Discrepancies,
digits = 0,
big.mark = ','
)
temp_shipper$Score <- round(temp_shipper$Score,2)
## set up dataset as a shared dataset for filtering ##
sd_shipper <- SharedData$new(temp_shipper,group='data_subset')
## actual visual in dashboard ##
bscols(
widths = c(4,4,4),
device = 'lg',
list(
filter_select(
id = 'origname',
label = 'Origin Name',
sharedData = sd_shipper,
group = ~OrigName,
multiple = TRUE
),
filter_checkbox(
id = 'ratecat',
label = 'Rate Category',
sharedData = sd_shipper,
group = ~RateCat,
allLevels = TRUE,
inline = TRUE
)
),
list(
filter_select(
id = 'origcity',
label = 'Origin City',
sharedData = sd_shipper,
group = ~OrigCity,
multiple = TRUE
),
filter_select(
id = 'ratecode',
label = 'Rate Code',
sharedData = sd_shipper,
group = ~RateCode,
multiple = TRUE
)
),
list(
filter_select(
id = 'origstate',
label = 'Origin State',
sharedData = sd_shipper,
group = ~OrigState,
multiple = TRUE
),
filter_select(
id = 'ratedesc',
label = 'Rate Description',
sharedData = sd_shipper,
group = ~RateDesc,
multiple = TRUE
)
)
)
datatable(
sd_shipper,
caption = ' ',
rownames = FALSE,
colnames = c(
'Orig Name',
'Orig City',
'OST',
'Rate Code',
'Description',
'Score',
'Discrepancy Ct',
'%',
'RateCate'
),
options = list(
pageLength = 5,
columnDefs = list(
list(className = 'dt-center', targets = c(2:3,5:7)),
list(visible = FALSE, targets = 8)
),
lengthChange = FALSE,
searching = FALSE
)
) %>%
formatCurrency(
'Discrepancies',
currency = '',
interval = 3,
mark = ',',
digits = 0
)
## receiver version ##
## set up data set ##
temp_receiver <- rate_lvl_recr %>%
subset(
select = c(
'DestName',
'DestCity',
'DestState',
'RateCode',
'RateDesc',
'Score',
'Discrepancies',
'DiscPer',
'RateCat'
)
)
temp_receiver <- temp_receiver[order(-temp_receiver$Score),]
temp_receiver$DiscPer <- paste(
formatC(
temp_receiver$DiscPer*100,
digits = 2,
format = 'f'
) %>% as.character(),
'%'
)
temp_receiver$Discrepancies <- formatC(
temp_receiver$Discrepancies,
digits = 0,
big.mark = ','
)
temp_receiver$Score <- round(temp_receiver$Score,2)
## set up dataset as a shared dataset for filtering ##
sd_receiver <- SharedData$new(temp_receiver,group='data_subset1')
## actual visual in dashboard ##
bscols(
widths = c(3,9),
device = 'lg',
list(
filter_select(
id = 'destname',
label = 'Destination Name',
sharedData = sd_receiver,
group =~DestName,
multiple = TRUE
),
filter_select(
id = 'destcity',
label = 'Destination City',
sharedData = sd_receiver,
group =~DestCity,
multiple = TRUE
),
filter_select(
id = 'deststate',
label = 'Destination State',
sharedData = sd_receiver,
group =~DestState,
multiple = TRUE
),
filter_checkbox(
id = 'ratecat',
label = 'Rate Category',
sharedData = sd_receiver,
group =~RateCat,
allLevels = TRUE,
inline = FALSE
),
filter_select(
id = 'ratecode',
label = 'Rate Code',
sharedData = sd_receiver,
group =~RateCode,
multiple = TRUE
),
filter_select(
id = 'ratedesc',
label = 'Rate Description',
sharedData = sd_receiver,
group =~RateDesc,
multiple = TRUE
)
),
datatable(
sd_receiver,
caption = 'RECEIVERS',
rownames = FALSE,
colnames = c(
'Dest Name',
'Dest City',
'DST',
'Rate Code',
'Description',
'Score',
'Discrepancy Ct',
'%',
'RateCate'
),
options = list(
pageLength = 10,
lengthMenu = c(5,10,15,20),
columnDefs = list(
list(className = 'dt-center', targets = c(2:3,5:7)),
list(visible = FALSE, targets = 8)
),
lengthChange = FALSE,
searching = FALSE
)
) %>%
formatCurrency(
'Discrepancies',
currency = '',
interval = 3,
mark = ',',
digits = 0
)
)
正如我所说,我没有收到任何错误消息,过滤器只是没有按预期更改其数据表。筛选器实际上并未筛选sharedData数据集中的任何行。即,当我单击费率类别filter_checkbox过滤器中的复选框时,我希望数据表中的“显示1到10,共1000个条目”会变为类似“显示1到10,共900个条目”,而这并非如此