r语言 - 在提交时将输入保存为.csv -单击提交什么也没有发生,但也没有错误



有一个小的仪表盘。当单击提交按钮时,没有错误,但也没有向文件写入任何内容。

代码如下:

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/

https://medium.com/@joyplumeri使用- r -的- -创造- web -调查-显示-即时反馈- - - - -数据存储在谷歌驱动- 68 f46eea0f8b

干杯~ !

我认为你的数据帧'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                  
)

相关内容

  • 没有找到相关文章

最新更新