【问题标题】:Is there an R function that gives a table as output when the input is taken from user?当输入来自用户时,是否有一个 R 函数可以将表格作为输出?
【发布时间】:2019-12-26 15:53:46
【问题描述】:

这是我用来获取用户输入的代码:

library(shiny)
ui<-fluidPage(
        textInput(inputId = "name",label = "Enter Name",value="abc"),
  radioButtons(inputId = "gender",
           label = "Select your gender",
           choices = c("Female","Male","Other"),selected = NULL),
  checkboxGroupInput(inputId = "hobbies",
                 label = "select your hobbies",
                 choices=c("reading","singing","coding","sports")),
  selectInput(inputId = "exam",label = "Select exam",
          choices=c("MHCET","HSC","SSC")),
  numericInput(inputId="marks",label="Enter Marks",value=60),
  selectInput(inputId = "stream",label = "Select stream",
          choices=c("CE","EXTC","MECH","IT","PPT")),
  dateInput(inputId = "dob",label = "Select DOB",
        value = NULL,min=NULL,max=NULL,format="dd-mm-yyyy",
        startview = "month",weekstart = NULL,language = "en",width = NULL),
  actionButton(inputId = "submit",label = "Submit"),
  )

server <- function(input, output, session) {
  observeEvent(input$submit,{   
print(as.table(input$name,input$gender,input$hobbies,input$exam,input$marks,input$stream,input$dob))
  })
}
shinyApp(ui=ui, server=server)

我需要找到一种方法以表格的形式显示输出。我尝试使用 file 函数来获取输入,但它不允许获取不同类型的输入。

我也尝试使用 print as.table 函数,但出现事件处理错误。

这个问题应该使用闪亮的库来解决。

【问题讨论】:

  • 你检查shiny::renderTable了吗?
  • SO 不适用于在硬件或培训课程中回答问题
  • 我确实尝试了 renderTable,但遇到了事件处理错误。

标签: r shiny


【解决方案1】:

是的,基础 Shiny 包中有渲染表和渲染数据表函数。 Hadley 关于 Shiny 的书对这些有很好的介绍 https://mastering-shiny.org/basic-ui.html#tables

【讨论】:

  • 谢谢。我会试一试
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-18
  • 2019-06-27
  • 2022-01-16
  • 2011-01-07
  • 2020-06-18
  • 2014-04-01
  • 1970-01-01
相关资源
最近更新 更多