r - 反应表:在闪亮中隐藏观察和编辑
问题描述
我正在创建一个响应式闪亮应用程序,我必须在其中编辑数据框并保存它。但在编辑部分,首先我想隐藏除选定行之外的所有其他观察。我想编辑它并再次选择一些观察并编辑它并再次保存等等。
我创建了一个示例数据,在这里我选择了一个国家并仅显示该国家的观察结果。我想编辑价格列,它应该在整体数据中更新,我需要保存它。然后稍后当我选择一个国家时,它会从编辑的数据中获取数据。并编辑它自动保存并继续
rm(list = ls())
library(shiny)
library(shinydashboard)
#--------------------------------
df <- data.frame("country" =c("Russia", "China", "US", "India", "UK" )
, "tv_cost" = c(43, 67, 78, 56, 78 )
, "fridge_cost" = c(78, 45, 56, 78, 47)
, "microwave" = c(44, 23,31,29, 34)
)
#Shiny Dashboard
ui <- dashboardPage(skin = "green"
, dashboardHeader(title = "Edit Table")
, dashboardSidebar(sidebarMenu(menuItem("Edit Data", tabName = "tab_01" )
, menuItem("Output", tabName = "tab_02")
, menuItem("Input", tabName = "tab_03")
))
, dashboardBody(tabItems(tabItem(tabName = "tab_01"
, selectInput(inputId = "countryid", label = "SELECT COUNTRY" , choices = df$country )
, DT::dataTableOutput("table1"))
, tabItem(tabName = "tab_02", DT::dataTableOutput("table2"))
, tabItem(tabName = "tab_03", DT::dataTableOutput("table3"))
))
)#dashboardpage ends here
server <- function(input, output, session){
#Creating a blank Data frame to update every change
df_02 <- reactive(df_03 <- NULL)
#Showing Data table, for editing, "I'm filtering data here but I have to hide other observation "
df_04 <- reactive(df %>%
filter(country == input$countryid ))
output$table1 <- renderDT({df_04()})
# saving the edit data
#Observing edited table
#updating it edited frame df_02
#Rendering overall edited df.
output$table2 <- renderDT({df_02()})
#input file
output$table3 <- renderDT({df})
}
shinyApp(ui, server)
提前致谢
解决方案
推荐阅读
- ansible - Ansible 不会通过 Telnet 连接到模拟网络设备
- c# - 图片的内容类型无效(.net core sdk 2.1)
- mysql - 使用 VARBINARY(max) 存储图像时出现 SQL 错误
- android - 无法解析来自 Android 支持存储库的导入(包括 Google 的 Maven)
- python - 循环遍历 pandas 的数据框行并比较列上的值
- java - java中Deques接口的addFirst(element)和push(element)方法有什么区别?
- apache-spark - spark aggregateByKey 添加额外的空行
- mysql - 在mysql中获取最近6个月的记录
- c# - IFormFile 在 asp.net core 2.1 中总是返回 null
- flutter - 如何实现 Flood-fill 算法?