从用户那里获取输入时,是否存在R函数可以将表格作为输出?

时间:2019-12-26 15:53:46

标签: r shiny

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

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)

我需要找到一种以表格形式显示输出的方法。我试图使用文件功能来接受输入,但是不允许接受不同类型的输入。

我还尝试使用print as.table函数,但是遇到了事件处理错误。

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

1 个答案:

答案 0 :(得分:0)

是的,基本的Shiny包中有render table和render datatable函数。哈德利(Hadley)关于Shiny的书很好地介绍了这些https://mastering-shiny.org/basic-ui.html#tables