![](/img/trans.png)
[英]Warning: replacing previous import 'DT::dataTableOutput' by 'shiny::dataTableOutput'
[英]Shiny inputDate and DT::dataTableOutput
我是 Shiny 的新手,對於我正在嘗試構建的應用程序來說,它似乎是一個了不起的工具。
我目前正在嘗試理解為什么 DT::dataTableOutput 命令無法讀取“inputDate”字段......例如,當我在界面中輸入 2021-01-01 時,表格顯示數字“18628”在“介紹日期”列中。
這是我的代碼,歡迎任何想法!
提前感謝社區,如果您需要更多/更好的信息來回答,請不要猶豫告訴我。
# Libraries to open
library(shiny)
library(DT)
# Save function
saveData <- function(data) {
data <- as.data.frame(t(data))
if (exists("responses")) {
responses <<- rbind(responses, data)
} else {
responses <<- data
}
}
loadData <- function() {
if (exists("responses")) {
responses
}
}
# Define the fields we want to save from the form
fields <- c("introduction_date","fish_species","cohort_id","cohort_size","initial_weight","cage_id","harvest_weight","allow_transfer") #,"transfer_density","cage_destination")
fish.names <- c("Dicentrarchus.labrax","Sparus.aurata","Argyrosomus.regius","Symphodus.ocellatus","Salmo.salar","Salmo.trutta","Oncorhynchus.mykiss")
# Shiny app with 3 fields that the user can submit data for
shinyApp(
ui <- fluidPage(
titlePanel("Project"),
sidebarLayout(
sidebarPanel(
dateInput("introduction_date", "Date:", value = "2021-01-01", format = "yyyy-mm-dd"),
selectInput("fish_species", "fish species",
fish.names),
numericInput("cohort_id", "cohort id", 10, min = 1, max = 100),
numericInput("cohort_size", "cohort size", 20000, min = 1, max = 100000),
sliderInput("initial_weight", "initial weight:",
0, 100, 15, ticks = FALSE),
numericInput("cage_id", "cage id", 10, min = 1, max = 100),
sliderInput("harvest_weight", "harvest weight",
200, 5000, 300, ticks = FALSE),
checkboxInput("allow_transfer", "allow transfer", FALSE),
actionButton("submit", "submit"),
actionButton("save_planning", "save planning", class = "btn-success"),
),
mainPanel(
tabsetPanel(
tabPanel("location", plotOutput("location"),
),
tabPanel("Planning", verbatimTextOutput("planning"),
DT::dataTableOutput("responses", width = 300), tags$hr(),
),
tabPanel("Table", tableOutput("table"))
)
)
)
),
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()
})
# When the Submit button is clicked, save the form data
observeEvent(input$save_plan, {
stopApp()
})
}
)
根據您的評論和formData
的評論,將您的formData
替換為:
formData <- reactive({
data <- sapply(fields, function(x) as.character(input[[x]]))
data
})
在運行之前重新啟動 R 會話。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.