r shiny:从以前持久存储的数据中加载数据以形成字段
r shiny: Load data in to form fields from previously persistent stored data
Dean Attali 的要点:https://gist.github.com/daattali/c4db11d81f3c46a7c4a5
在本例中:可以输入、提交和保存数据(持久数据存储)。您可以在提交后出现的 table 中看到提交的数据。随着时间的推移,table 随着不同的条目而增长。到目前为止还没有可能加载提交表单中的数据来更改或更新提交?!
我的问题:是否可以将以前提交的数据不仅加载到 table,而且加载到字段(名称、使用闪亮、r 年数)?
我想更新条目并将它们保存回来。
我知道增删改查。我想知道 Dean Attali 的持久数据存储示例是否可行。谢谢!
library(shiny)
# Define the fields we want to save from the form
fields <- c("name", "used_shiny", "r_num_years")
# Save a response
# ---- This is one of the two functions we will change for every storage type ----
saveData <- function(data) {
data <- as.data.frame(t(data))
if (exists("responses")) {
responses <<- rbind(responses, data)
} else {
responses <<- data
}
}
# Load all previous responses
# ---- This is one of the two functions we will change for every storage type ----
loadData <- function() {
if (exists("responses")) {
responses
}
}
# Shiny app with 3 fields that the user can submit data for
shinyApp(
ui = fluidPage(
DT::dataTableOutput("responses", width = 300), tags$hr(),
textInput("name", "Name", ""),
checkboxInput("used_shiny", "I've built a Shiny app in R before", FALSE),
sliderInput("r_num_years", "Number of years using R", 0, 25, 2, ticks = FALSE),
actionButton("submit", "Submit")
),
server = function(input, output, session) {
# Whenever a field is filled, aggregate all form data
formData <- reactive({
data <- sapply(fields, function(x) input[[x]])
data
})
# When the Submit button is clicked, save the form data
observeEvent(input$submit, {
saveData(formData())
})
# Show the previous responses
# (update with current response when Submit is clicked)
output$responses <- DT::renderDataTable({
input$submit
loadData()
})
}
)
我现在完全找到了我要找的东西:https://www.r-bloggers.com/shiny-crud-app/
此 post 将逐步向您展示如何构建一个 Shiny 应用程序,让您可以在 table.
中创建、更新和删除数据
您可以在此处查看正在运行的应用程序:https://gluc.shinyapps.io/crud
完整的 source-code 在此要点中:https://gist.github.com/gluc/d39cea3d11f03542970b
现在下一步是合并:提交、新建、删除并保存到例如 csv 文件。
我会试试的!
Dean Attali 的要点:https://gist.github.com/daattali/c4db11d81f3c46a7c4a5 在本例中:可以输入、提交和保存数据(持久数据存储)。您可以在提交后出现的 table 中看到提交的数据。随着时间的推移,table 随着不同的条目而增长。到目前为止还没有可能加载提交表单中的数据来更改或更新提交?!
我的问题:是否可以将以前提交的数据不仅加载到 table,而且加载到字段(名称、使用闪亮、r 年数)? 我想更新条目并将它们保存回来。 我知道增删改查。我想知道 Dean Attali 的持久数据存储示例是否可行。谢谢!
library(shiny)
# Define the fields we want to save from the form
fields <- c("name", "used_shiny", "r_num_years")
# Save a response
# ---- This is one of the two functions we will change for every storage type ----
saveData <- function(data) {
data <- as.data.frame(t(data))
if (exists("responses")) {
responses <<- rbind(responses, data)
} else {
responses <<- data
}
}
# Load all previous responses
# ---- This is one of the two functions we will change for every storage type ----
loadData <- function() {
if (exists("responses")) {
responses
}
}
# Shiny app with 3 fields that the user can submit data for
shinyApp(
ui = fluidPage(
DT::dataTableOutput("responses", width = 300), tags$hr(),
textInput("name", "Name", ""),
checkboxInput("used_shiny", "I've built a Shiny app in R before", FALSE),
sliderInput("r_num_years", "Number of years using R", 0, 25, 2, ticks = FALSE),
actionButton("submit", "Submit")
),
server = function(input, output, session) {
# Whenever a field is filled, aggregate all form data
formData <- reactive({
data <- sapply(fields, function(x) input[[x]])
data
})
# When the Submit button is clicked, save the form data
observeEvent(input$submit, {
saveData(formData())
})
# Show the previous responses
# (update with current response when Submit is clicked)
output$responses <- DT::renderDataTable({
input$submit
loadData()
})
}
)
我现在完全找到了我要找的东西:https://www.r-bloggers.com/shiny-crud-app/ 此 post 将逐步向您展示如何构建一个 Shiny 应用程序,让您可以在 table.
中创建、更新和删除数据您可以在此处查看正在运行的应用程序:https://gluc.shinyapps.io/crud
完整的 source-code 在此要点中:https://gist.github.com/gluc/d39cea3d11f03542970b
现在下一步是合并:提交、新建、删除并保存到例如 csv 文件。 我会试试的!