При построении кадра данных целые числа равны numeric()
. Я также добавил reactiveValues
, чтобы вы могли поместить свой фрейм данных в. Если вы хотите, чтобы данные сбрасывались при каждом посещении, вы можете поместить v$df <- data.frame(Company =...
в server
часть приложения
library(shiny)
library(DT)
ui <- fluidPage(
titlePanel("Cost tool "),
sidebarLayout(
sidebarPanel(
selectInput(inputId = "Company", label = "Company",
choices = list("Company 1", "Company 2 " , " Company 3 "), selected = ""),
radioButtons(inputId = "Goods", label = "Select bought goods",inline = TRUE,
choices = list("Food", "Electronics","Books"), selected = ""),
selectInput(inputId = "GoodsType", label = " Types of Goods",
choices = list(" Milk", "Eggs" , "vegetables" ,"Games Consoles",
"headphones", "phones", "mystery","fiction","horror"), selected = ""),
textInput(inputId = "Number", label = " How many?: ",value = ""),
textInput(inputId = "Cost", label = "Cost",value = ""),
actionButton("submit","Submit")
),
mainPanel(
DT::dataTableOutput("CostTable")
)
)
)
v <- reactiveValues()
v$df <- data.frame(Company = character(), Goods = character(),GoodsType = character(),
Number = numeric(), Cost = numeric(), stringsAsFactors = FALSE)
server <- function(input, output, session){
observeEvent(input$submit,{
req(input$Company,input$Goods,input$GoodsType,input$Number,input$Cost)
tmp <- data.frame(Company = input$Company,Goods = input$Goods,GoodsType = input$GoodsType, Number = input$Number,Cost = input$Cost)
v$df <- rbind(v$df,tmp)
})
output$CostTable <- DT::renderDataTable({
v$df
})
}
shinyApp(ui = ui, server = server)