【问题标题】:download the dataset in R shiny在 R 中下载数据集闪亮
【发布时间】: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 &lt;- ...; server &lt;- ...; shinyApp(ui, server)、或app.R 布局或ui.R/server.R/global.R构造。

标签: r shiny download render dt


【解决方案1】:

mathdat()write.csv(mathdat,file,row.names = FALSE) 中应该是mathdat,除非您在其他地方定义了响应式数据框。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-18
    • 2017-11-03
    • 1970-01-01
    • 2020-07-27
    • 2019-09-27
    • 1970-01-01
    • 1970-01-01
    • 2015-03-09
    相关资源
    最近更新 更多