在提交时将输入保存到 .csv - 单击提交没有任何反应,但也没有错误
Save input to .csv on submit - Click submit nothing happens, but not errors either
有一个小仪表板。
单击提交按钮时没有错误,但也没有任何内容写入文件。
代码如下所示:
library(shiny)
library(shinydashboard)
library(googlesheets4)
library(markdown)
library(DT)
library(ggplot2)
library(plotly)
library(rmarkdown)
library(knitr)
library(pander)
# Load local test data
dbrp_data2 <- read.csv(file = 'location of locally stored .csv file')
# Define the fields we want to save from the form
# Dashboard page
ui <- dashboardPage(
# Begin dashboard header
dashboardHeader(title = "DBRP"),
# Begin dashboard sidebar
dashboardSidebar(
# Begin sidebar menu
sidebarMenu(
menuItem("Artifact Entry", tabName = "artifactentry")
# End sidebar menu
)
# End Dashboard sidebar
),
# Begin dashboard body
dashboardBody(
# Begin tab items by tab name
tabItems(
# Begin first tab item
tabItem(tabName = "artifactentry", h2("Artifact Entry"),
# Begin first fluid row - artifact entry for submit and reset buttons
fluidRow(
# Begin first box of first fluid row - artifact entry
box(h3("Submit or Reset Data"), width = 7,
# Begin first column of first box of first fluid row - artifact entry
column(3, h4("Submit Data"),
# Submit action button
actionButton("submit_artifact_entry", label = "Submit")
# End first column of first box of first fluid row - artifact entry
),
# Begin second column of first box of first fluid row - artifact entry
column(3, h4("Reset Entries"),
# Reset action button
actionButton("reset_artifact_entry", label = "Reset")
# End second column of first box of first fluid row - artifact entry
)
# End first box of first tab item - artifact entry
)
# End first fluid row - artifact entry for submit and reset buttons
),
# Begin second fluid row - widgets to test area
fluidRow(
# Begin box of second fluidRow - widgets to test area
box(h3("Widgets to Test"),
# Begin first column of second fluidRow - widgets to test
column(4, h4("Widgets"),
# Checkbox widget to test
checkboxGroupInput("dbir", selected = NULL,
h4("Select Rating"),
c(
"Low" = "Low",
"Medium" = "Medium",
"High" = "High",
"Critical" = "Critical"
)
# End checkbox widget to test
)
# End box of second fluidRow - widgets to test area
)
# End box second fluidRow - widgets to test
)
# End second fluidRow - widgets to test area
)
# End first tab item
)
# End tab items by tab name
)
# End dashboard body
)
# End dashboard page
)
# Begin server functions
server <- function(input, output, session) {
# Rest button for artifact entry page
observeEvent(input$reset_artifact_entry, {
# Reset data breach rating check box
updateCheckboxGroupInput(session, "dbir", choices = c(
"Low" = "Low",
"Medium" = "Medium",
"High" = "High",
"Critical" = "Critical"), selected = NULL)
})
observeEvent(input$submit_artifact_entry, {
submit <- data.frame(dbir = input$dbir)
# append write of data on submit
write.table(submit, "dbrp_test_data2.csv",
append = TRUE,
col.names = FALSE
)
})
# End server functions
}
shinyApp(ui, server)
如何将 checkboxGroupInput 中的值放入文件中,每次单击提交时数据都会附加到该文件中?
我已经查阅了一些参考资料,但我现在比受过教育的人更困惑...叹气...
https://psyteachr.github.io/shiny-tutorials/index.html
https://psyteachr.github.io/shiny-tutorials/data-input.html#02_try_the_demo
https://github.com/ConalMonaghan/Shiny-Survey-and-Feedback-Site
https://www.learnbyexample.org/read-and-write-csv-files-in-r/
干杯~!
我认为您的数据框 'submit' 必须首先是反应值或多个值的占位符。
ui:
your part from above
server:
submit <- reactiveValues()
submit$some_variable_name<- data.frame(dbir = input$dbir)
write.table(submit$some_variable_name, "dbrp_test_data2.csv",
append = TRUE,
col.names = FALSE
)
有一个小仪表板。 单击提交按钮时没有错误,但也没有任何内容写入文件。
代码如下所示:
library(shiny)
library(shinydashboard)
library(googlesheets4)
library(markdown)
library(DT)
library(ggplot2)
library(plotly)
library(rmarkdown)
library(knitr)
library(pander)
# Load local test data
dbrp_data2 <- read.csv(file = 'location of locally stored .csv file')
# Define the fields we want to save from the form
# Dashboard page
ui <- dashboardPage(
# Begin dashboard header
dashboardHeader(title = "DBRP"),
# Begin dashboard sidebar
dashboardSidebar(
# Begin sidebar menu
sidebarMenu(
menuItem("Artifact Entry", tabName = "artifactentry")
# End sidebar menu
)
# End Dashboard sidebar
),
# Begin dashboard body
dashboardBody(
# Begin tab items by tab name
tabItems(
# Begin first tab item
tabItem(tabName = "artifactentry", h2("Artifact Entry"),
# Begin first fluid row - artifact entry for submit and reset buttons
fluidRow(
# Begin first box of first fluid row - artifact entry
box(h3("Submit or Reset Data"), width = 7,
# Begin first column of first box of first fluid row - artifact entry
column(3, h4("Submit Data"),
# Submit action button
actionButton("submit_artifact_entry", label = "Submit")
# End first column of first box of first fluid row - artifact entry
),
# Begin second column of first box of first fluid row - artifact entry
column(3, h4("Reset Entries"),
# Reset action button
actionButton("reset_artifact_entry", label = "Reset")
# End second column of first box of first fluid row - artifact entry
)
# End first box of first tab item - artifact entry
)
# End first fluid row - artifact entry for submit and reset buttons
),
# Begin second fluid row - widgets to test area
fluidRow(
# Begin box of second fluidRow - widgets to test area
box(h3("Widgets to Test"),
# Begin first column of second fluidRow - widgets to test
column(4, h4("Widgets"),
# Checkbox widget to test
checkboxGroupInput("dbir", selected = NULL,
h4("Select Rating"),
c(
"Low" = "Low",
"Medium" = "Medium",
"High" = "High",
"Critical" = "Critical"
)
# End checkbox widget to test
)
# End box of second fluidRow - widgets to test area
)
# End box second fluidRow - widgets to test
)
# End second fluidRow - widgets to test area
)
# End first tab item
)
# End tab items by tab name
)
# End dashboard body
)
# End dashboard page
)
# Begin server functions
server <- function(input, output, session) {
# Rest button for artifact entry page
observeEvent(input$reset_artifact_entry, {
# Reset data breach rating check box
updateCheckboxGroupInput(session, "dbir", choices = c(
"Low" = "Low",
"Medium" = "Medium",
"High" = "High",
"Critical" = "Critical"), selected = NULL)
})
observeEvent(input$submit_artifact_entry, {
submit <- data.frame(dbir = input$dbir)
# append write of data on submit
write.table(submit, "dbrp_test_data2.csv",
append = TRUE,
col.names = FALSE
)
})
# End server functions
}
shinyApp(ui, server)
如何将 checkboxGroupInput 中的值放入文件中,每次单击提交时数据都会附加到该文件中?
我已经查阅了一些参考资料,但我现在比受过教育的人更困惑...叹气...
https://psyteachr.github.io/shiny-tutorials/index.html
https://psyteachr.github.io/shiny-tutorials/data-input.html#02_try_the_demo
https://github.com/ConalMonaghan/Shiny-Survey-and-Feedback-Site
https://www.learnbyexample.org/read-and-write-csv-files-in-r/
干杯~!
我认为您的数据框 'submit' 必须首先是反应值或多个值的占位符。
ui:
your part from above
server:
submit <- reactiveValues()
submit$some_variable_name<- data.frame(dbir = input$dbir)
write.table(submit$some_variable_name, "dbrp_test_data2.csv",
append = TRUE,
col.names = FALSE
)