화면 상단에 data.frame 정보와 하단에 특정 변수 통계를 표시하는 Shiny 앱을 만듭니다. 사용자는 DT::datatable
객체와 상호 작용하여 data.frame 열을 탐색 할 수 있습니다.위치를 유지하면서 Shiny DataTable의 행을 업데이트하십시오.
사용자가 변수를 클릭하면 편집 할 수있는 세부 정보가 표시됩니다. 이 정보가 업데이트되어 데이터 테이블에 반영되기를 바랍니다. 내 문제는 내가 테이블을 업데이트 할 때, 렌더링되고 처음부터 표시되는 것입니다. 편집 후 데이터 테이블의 페이지 및 행 선택을 유지하려면 어떻게해야합니까?
다음은 mtcars 데이터 집합을 DT::datatable
에 표시하는 최소 작업 예제입니다. 필드를 업데이트하는 컨트롤이 있습니다. datatable은 첫 번째 페이지로 다시 렌더링됩니다.
library(shiny)
runApp(shinyApp(
ui = fluidPage(
title = "minimal-working-example",
fluidRow(
column(3, inputPanel(
selectInput("field", "Field", choices = names(mtcars)),
numericInput("value", "Value", 0),
actionButton("submit", "Submit")
)),
column(9,
DT::dataTableOutput("table")
)
)
),
server = function(input, output) {
v <- reactiveValues(mtcars=mtcars)
observeEvent(input$submit, {
v$mtcars[input$field] <- input$value
})
output$table <- DT::renderDataTable({
DT::datatable(
v$mtcars,
selection = "single",
options = list(pageLength = 5))
})
}
))
세션 정보 :
이 그와 같은 JS를 통해datatable
의 구조 또는 무언가로받지 않고 R 내부에서 수행 할 수 있습니다
Session info --------------------------
setting value
version R version 3.3.0 (2016-05-03)
system x86_64, mingw32
ui RStudio (0.99.902)
language (EN)
collate English_United States.1252
tz America/Chicago
date 2016-07-11
Packages -------------------------------
package * version date source
DT 0.1.45 2016-02-09 Github (rstudio/[email protected])
shiny * 0.13.0.9000 2016-02-08 Github (rstudio/[email protected])
이 까다로운하지만 행할 수있다. 본질적으로 일어날 필요가있는 것은 테이블의 현재 페이지가 반응 적으로 저장되어야하며, 이는 자바 스크립트에서'Shiny.onInputChange'로 수행 될 수 있습니다. 그런 다음 콜백 테이블을 렌더링하면 이전에 있던 페이지 번호에서 열 수 있습니다. 나는 기회가 생길 때 완전한 대답을 쓸거야. – Carl