【发布时间】:2020-07-27 17:03:16
【问题描述】:
我是 R shiny 的新手,我将下载我正在查看的数据集,但它显示“未使用的参数 (mainPanel(dowloadButton("downloadDatable", "Download the Dataset")))”。你能帮我吗?非常感谢您的帮助。
library(shiny)
# Read the data
temp <- tempfile()
download.file("http://archive.ics.uci.edu/ml/machine-learning-databases/00356/student.zip",
temp, mode="wb")
unzip(temp, "student-mat.csv")
mathdat <- read.table("student-mat.csv",sep= ";", header= T)
unlink(temp)
# UI part
shinyUI(navbarPage(
title = 'DataTable Options',
tabPanel('Display length', DT::dataTableOutput('table.sub_1')),
tabPanel('Length menu', DT::dataTableOutput('table.sub_2')),
),
mainPanel(
dowloadButton("downloadDatable", "Download the Dataset"))
)
# Server part
shinyServer(function(input, output, session) {
# display 10 rows initially
output$table.sub_1 <- DT::renderDataTable(
DT::datatable(mathdat, options = list(pageLength = 25))
)
# -1 means no pagination; the 2nd element contains menu labels
output$table.sub_2 <- DT::renderDataTable(
DT::datatable(
mathdat, options = list(
lengthMenu = list(c(5, 15, -1), c('5', '15', 'All')),
pageLength = 15
)
)
)
# Download the datatable
output$downloadDatable <- downloadHandler(
filename = function(){paste("Student Performance in Math.csv")},
content = function(file){write.csv(mathdat(), file, row.names = FALSE)}
)
})
【问题讨论】:
-
是拼写错误,还是你定义了(某处)一个名为
dowloadButton的类似名称的函数? -
该特定错误是因为您将第二个参数
mainPanel(...)传递给shinyUI,它接受单个参数ui=。我建议您(再次)查看教程或图库中的一些shiny演示以查看建议的布局,包括ui <- ...; server <- ...; shinyApp(ui, server)、或app.R布局或ui.R/server.R/global.R构造。
标签: r shiny download render dt