当试图在传单/ DT之间渲染带有串扰的html应用时,我收到以下错误:
Error in datatable(sd, extensions = "Scroller", style = "bootstrap", class = "compact", : 'data' must be 2-dimensional (e.g. data frame or matrix)
数据框:
df2 <- data.frame(
structure(list(lat = c(-20.42, -20.62, -26, -17.97, -20.42, -19.68,
-11.7, -28.11, -28.74, -17.47, -21.44, -12.26, -18.54, -21, -20.7,
-15.94, -13.64, -17.83, -23.5, -22.63), long = c(181.62, 181.03,
184.1, 181.66, 181.96, 184.31, 166.1, 181.93, 181.74, 179.59,
180.69, 167, 182.11, 181.66, 169.92, 184.95, 165.96, 181.5, 179.78,
180.31), depth = c(562L, 650L, 42L, 626L, 649L, 195L, 82L, 194L,
211L, 622L, 583L, 249L, 554L, 600L, 139L, 306L, 50L, 590L, 570L,
598L), mag = c(4.8, 4.2, 5.4, 4.1, 4, 4, 4.8, 4.4, 4.7, 4.3,
4.4, 4.6, 4.4, 4.4, 6.1, 4.3, 6, 4.5, 4.4, 4.4), stations = c(41L,
15L, 43L, 19L, 11L, 12L, 43L, 15L, 35L, 19L, 13L, 16L, 19L, 10L,
94L, 11L, 83L, 21L, 13L, 18L)), .Names = c("lat", "long", "depth",
"mag", "stations"), row.names = c(NA, 20L), class = "data.frame")
)
可重复的代码:
library(crosstalk)
library(leaflet) #devtools::install_github('rstudio/leaflet', force = TRUE)
library(DT)
# Wrap data frame in SharedData
sd <- SharedData$new(quakes[sample(nrow(quakes), 10),])
# Create a filter input
filter_slider("mag", "Magnitude", sd, column=~mag, step=0.1, width=250)
# Use SharedData like a dataframe with Crosstalk-enabled widgets
bscols(
leaflet(sd) %>% addTiles() %>% addMarkers(),
datatable(sd, extensions="Scroller", style="bootstrap", class="compact", width="100%",
options=list(deferRender=TRUE, scrollY=300, scroller=FALSE))
)
平台和pkg版本: R版本3.3.2(2016-10-31) crosstalk_1.0.1(从devtools / github安装#) leaflet_1.0.2.9010 DT_0.2
答案 0 :(得分:8)
从devtool / github安装'DT'。
devtools::install_github('rstudio/DT')