如何解决as.data.frame.default 中的错误:无法将类强制转换为 data.frame - 将按钮提交到 .csv
我正在尝试从 checkBoxGroupInput 获取用户输入并将其附加到加载的 .csv
运行应用程序时出现错误:
as.data.frame.default 中的错误:无法将类强制转换为 data.frame
我显然在代码的服务器部分有点迷失了。我的重置按钮工作得很好,我对那里的语法如何工作有某种了解。我也有点不利,因为我没有使用谷歌表格作为解决方案的一部分,我试图遵循的例子使用谷歌表格,所以关于更新表格的代码部分让我失望。
这是目前的代码:
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
# Libraries to load
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_data <- read.csv(file = '/home/osrs/dbrp_data.csv')
dbrp_data1 <- read.csv(file = '/home/osrs/dbrp_test_data1.csv')
# 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","Critical" = "Critical"),selected = NULL)
})
observeEvent(input$submit_artifact_entry,{
submit <- reactive(c(
input$dbir
)
)
# append write of data on submit
write.table(submit,"dbrp_test_data1.csv",append = TRUE
)
})
# End server functions
}
shinyApp(ui,server)
干杯~!
更新:
我将服务器中的代码更改为:
observeEvent(input$submit_artifact_entry,{
submit <- data.frame(c(
input$dbir
)
)
# append write of data on submit
write.table(submit,append = TRUE
)
当我点击提交时它不再使应用程序崩溃,但是每次我点击提交时我都会收到这个错误:
write.table(submit,append = TRUE) 中的警告: 将列名附加到文件 write.table(submit,append = TRUE) 中的警告: 将列名附加到文件
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。