在应用程序中保留rhandsontable的行顺序
我正在运行一个来自的示例在应用程序中保留rhandsontable的行顺序,r,shiny,R,Shiny,我正在运行一个来自的示例 库(rhandsontable) 图书馆(闪亮) runApp(shinyApp)( ui=fluidPage(rHandsontableOutput(“热”)), 服务器=功能(输入、输出、会话){ fname回答此问题的最佳方式是在提交问题。目前,这些问题仅定义了部分handsontable事件列表。此列表不包括您需要的afterColumnSort。下面是一个快速破解部分回答您的问题 library(rhandsontable) library(shiny) li
库(rhandsontable)
图书馆(闪亮)
runApp(shinyApp)(
ui=fluidPage(rHandsontableOutput(“热”)),
服务器=功能(输入、输出、会话){
fname回答此问题的最佳方式是在提交问题。目前,这些问题仅定义了部分handsontable
事件列表。此列表不包括您需要的afterColumnSort
。下面是一个快速破解部分回答您的问题
library(rhandsontable)
library(shiny)
library(htmlwidgets)
runApp(shinyApp(
ui = fluidPage(
rHandsontableOutput("hot"),
tags$script(
'
setTimeout(
function() {
HTMLWidgets.find("#hot").hot.addHook(
"afterColumnSort",
function(){
console.log("sort",this);
Shiny.onInputChange(
"hot_sort",
{
data: this.getData()
}
)
}
)
},
1000
)
'
)
),
server = function(input, output, session) {
observeEvent(
input$hot_sort
,{
print(input$hot_sort$data)
}
)
output$hot <- renderRHandsontable({
if (!is.null(input$hot)) {
DF <- hot_to_r(input$hot)
} else {
DF <- mtcars
}
rhandsontable(DF) %>%
hot_table(highlightCol = TRUE, highlightRow = TRUE) %>%
hot_cols(columnSorting = TRUE)
})
}
))
库(rhandsontable)
图书馆(闪亮)
库(htmlwidgets)
runApp(shinyApp)(
ui=fluidPage(
rHandsontableOutput(“热”),
标记$script(
'
设置超时(
函数(){
HTMLWidgets.find(“#hot”).hot.addHook(
“后列排序”,
函数(){
console.log(“sort”,this);
发亮的。输入改变(
“热门排序”,
{
数据:this.getData()
}
)
}
)
},
1000
)
'
)
),
服务器=功能(输入、输出、会话){
敏锐的(
输入$hot\u排序
,{
打印(输入$hot\U sort$数据)
}
)
output$hot我不认为有任何方法可以在数据表中为闪亮、悲伤的对象保留排序列
使用下面的代码,我可以将shiny app中所做的更改保存到文件mtcars2.csv
。有趣的是!按所需列进行排序后,单击任意数据单元格并按enter键将行顺序保存到mtcars2.csv
。同意timelyportolio
在git上提交问题的观点
R代码:
库(闪亮)
图书馆(rhandsontable)
runApp(shinyApp)(
ui=fluidPage(标题面板(“编辑数据文件”),
helpText(“对表所做的更改将自动保存到源文件中。”),
#操作按钮(“saveBtn”、“Save”),
rHandsontableOutput(“热”),
shinyServer(功能(输入、输出、会话){
值=反应值()
数据=无功({
如果(为空(输入$hot)){
hot=read.csv(“mtcars.csv”,stringsAsFactors=FALSE)
}否则{
热=热到热(输入$hot)
}
#这将用作函数输入
值[[“热”]]=热
热的
})
观察({
#输入$saveBtn
如果(!为.null(值[[“热”]])){
write.csv(值[[“hot”]],“mtcars.csv”,row.names=FALSE)
}
})
输出$hot%
热表(highlightCol=TRUE,highlightRow=TRUE)%>%
热列(列排序=真)
热的
}
})
})
))
library(rhandsontable)
library(shiny)
library(htmlwidgets)
runApp(shinyApp(
ui = fluidPage(
rHandsontableOutput("hot"),
tags$script(
'
setTimeout(
function() {
HTMLWidgets.find("#hot").hot.addHook(
"afterColumnSort",
function(){
console.log("sort",this);
Shiny.onInputChange(
"hot_sort",
{
data: this.getData()
}
)
}
)
},
1000
)
'
)
),
server = function(input, output, session) {
observeEvent(
input$hot_sort
,{
print(input$hot_sort$data)
}
)
output$hot <- renderRHandsontable({
if (!is.null(input$hot)) {
DF <- hot_to_r(input$hot)
} else {
DF <- mtcars
}
rhandsontable(DF) %>%
hot_table(highlightCol = TRUE, highlightRow = TRUE) %>%
hot_cols(columnSorting = TRUE)
})
}
))
library(shiny)
library(rhandsontable)
runApp(shinyApp(
ui = fluidPage(titlePanel("Edit Data File"),
helpText("Changes to the table will be automatically saved to the source file."),
# actionButton("saveBtn", "Save"),
rHandsontableOutput("hot")),
shinyServer(function(input, output, session) {
values = reactiveValues()
data = reactive({
if (is.null(input$hot)) {
hot = read.csv("mtcars.csv", stringsAsFactors = FALSE)
} else {
hot = hot_to_r(input$hot)
}
# this would be used as a function input
values[["hot"]] = hot
hot
})
observe({
# input$saveBtn
if (!is.null(values[["hot"]])) {
write.csv(values[["hot"]], "mtcars.csv", row.names = FALSE)
}
})
output$hot <- renderRHandsontable({
hot = data()
if (!is.null(hot)) {
hot = rhandsontable(hot) %>%
hot_table(highlightCol = TRUE, highlightRow = TRUE) %>%
hot_cols(columnSorting = TRUE)
hot
}
})
})
))