闪亮的数据源可编辑,用于反应性数据源

发布于 2025-02-01 05:16:11 字数 1941 浏览 3 评论 0原文

我只是想制作用户可编辑选择的数据(在闪亮的数据表中显示),并最终将用户的更新保存到文件(例如excel文件),请参见下面的测试代码:

我检查了下面的示例/问题。 (还有其他一些),但是没有一个将反应性用作数据源。

https://yihui.shinyapps.io/dt-edit/

https://stackoverflow.com/questions/69959720/Edit-DataTable-in-shiny-with-dropdown-selection-for-dt-v0-19"> dt-dt-v0-19"> editit DataTable在下拉菜单中闪闪发光(用于DT V0.19) /a>

DT: Dynamically change column基于从R Shiny App中的另一列中的SelectInput的值

以下代码的问题是:当我尝试更新第二个单元格时,我在第一个单元格中进行的更新消失了。

library(shiny)
library(DT)
#> 
#> Attaching package: 'DT'
#> The following objects are masked from 'package:shiny':
#> 
#>     dataTableOutput, renderDataTable


ui <- fluidPage(
  selectInput("data", "Select a dataset:", choices = c("iris", "mtcars")),
  DTOutput("t1"),
  actionButton("save", "Save")
)

server <- function(input, output, session) {
  tempdf <- NULL

  data <- reactive({
    head(get(input$data))
  })

  output$t1 <- renderDT({
    data()
  }, editable = "cell")

  proxyt1 <- dataTableProxy("t1")

  observeEvent(input$t1_cell_edit, {
    info <- input$t1_cell_edit
    str(info)
    tempdf <<- editData(data(), info)
    # tempdf <<- editData(isolate(data()), info)

    replaceData(proxyt1, tempdf, resetPaging = FALSE)
  })

  # observeEvent(input$save, {
  #   writexl::write_xlsx(tempdf, "~/test.xlsx")
  # })
}

shinyApp(ui, server)
#> PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.
Shiny applications not supported in static R Markdown documents

I just wanted to make the data (displayed in the shiny datatable) selected by user editable and eventually to save the user's updates to a file (e.g. such as an excel file), see the testing code below:

I checked the example/questions below(and a few others), but none of those used the reactive as the data source.

https://yihui.shinyapps.io/DT-edit/

Edit datatable in shiny with dropdown selection (for DT v0.19)

DT: Dynamically change column values based on selectinput from another column in R shiny app

The issue for the code below is: when I try to update the second cell, the updates I made in the first cell disappeared.

library(shiny)
library(DT)
#> 
#> Attaching package: 'DT'
#> The following objects are masked from 'package:shiny':
#> 
#>     dataTableOutput, renderDataTable


ui <- fluidPage(
  selectInput("data", "Select a dataset:", choices = c("iris", "mtcars")),
  DTOutput("t1"),
  actionButton("save", "Save")
)

server <- function(input, output, session) {
  tempdf <- NULL

  data <- reactive({
    head(get(input$data))
  })

  output$t1 <- renderDT({
    data()
  }, editable = "cell")

  proxyt1 <- dataTableProxy("t1")

  observeEvent(input$t1_cell_edit, {
    info <- input$t1_cell_edit
    str(info)
    tempdf <<- editData(data(), info)
    # tempdf <<- editData(isolate(data()), info)

    replaceData(proxyt1, tempdf, resetPaging = FALSE)
  })

  # observeEvent(input$save, {
  #   writexl::write_xlsx(tempdf, "~/test.xlsx")
  # })
}

shinyApp(ui, server)
#> PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.

Shiny applications not supported in static R Markdown documents

Created on 2022-05-23 by the reprex package (v2.0.1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文