我正在尝试选择DataTable中的单元格并显示相应的位置/值。 但似乎没有用......我从the example cell code from Yihui运行了代码,但仍然显示出与我的代码相同的错误:
以下是我的代码的一部分。
biTableMatrix函数 - 它通过xpos(行)和ypos(列)将值分配给矩阵/ df中的某个位置。首先它返回一个矩阵,但我认为错误可能是由对象类型(矩阵而不是示例中的data.frame)引起的,所以我将它转换为data.frame - 对你没什么帮助...
<TabControl ItemsSource="{Binding MyTabItems}">
<TabControl.Resources>
<DataTemplate DataType="{x:Type viewModels:MyTabItemViewModel}">
<views:MyTabItem/>
</DataTemplate>
</TabControl.Resources>
<TabControl.ItemContainerStyle>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Header" Value="{Binding Path=Header}"/>
<Setter Property="ContextMenu">
<Setter.Value>
<ContextMenu>
<MenuItem Header="Delete" Click="Delete_OnClick"/>
</ContextMenu>
</Setter.Value>
</Setter>
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
// In code behind I have this method that should be triggered when the
// Delete MenuItem is clicked
private void Delete_OnClick(object sender, RoutedEventArgs e)
{
var tabItem = (ITabItem) sender;
ViewModel.DeleteTab(tabItem);
}
供参考,这是我的ui.R
# The following are in helper.R
travelMeans <- c('02', '04')
prepareTwoMeans <- function(travelMeans) {
listx <- subset(geodata[geodata$MeanCode==travelMeans[1],], select = -c( AreaFull,MeanName,MeanFull))
listx <- listx[order(listx$Percentage),]
listy <- subset(geodata[geodata$MeanCode==travelMeans[2],], select = -c( AreaFull,MeanName,MeanFull,AreaCode))
listy <- listy[order(listy$Percentage),]
listx$xpos <- seq(length=nrow(listx))
listy$ypos <- seq(length=nrow(listy))
listx <- merge(listx, listy, by.x = c("AreaName"), by.y = c("AreaName"), all=TRUE)
return(listx)
}
# This function generates the two-way table of two travel means
biTableMatrix <- function(travelMeans) {
fullList <- prepareTwoMeans(travelMeans)
len <- length(fullList$AreaName)
biTableMat <- matrix(data = "", nrow = len, ncol = len, dimnames = list(seq(length = len), seq(length = len)))#,
for (n in 1:len) {
x <- fullList$xpos[n]
y <- fullList$ypos[n]
biTableMat[x,y] <- as.character(fullList$AreaName[n]) #fullList$AreaCode[n]
}
return(as.data.frame(biTableMat) )
}
# The following are in server.R
biTable <- reactive({
return(biTableMatrix(input$travelMeans))
})
output$biTable <- DT::renderDataTable({
DT::datatable(
biTable()
, selection = list(mode = "single", target = "cell")
, extensions = list("Scroller", "RowReorder")
, options = list(
scrollX = 500
, scrollY = 700
, rowReorder = FALSE
)
)}
, options = list(
searchHighlight = TRUE
)
)
output$biTableText <- renderPrint(input$biTable_cells_selected$value)
任何帮助都将非常感谢!!
谢谢!
答案 0 :(得分:-2)
A,b
请勿使用曲线DT。