How to display data in MainPanel based on user selection in Shiny R?

北慕城南 提交于 2019-12-02 08:34:51

Option 1:

You ca use req() to ensure that input$slct must be available for the table to be displayed.

You only need to change your server code:

server <- function(input, output) {
    #df$system<-rownames(df$Systems)
    output$mytable = DT::renderDataTable({
        req(input$slct) # add this line
        df %>%
            filter(stringr::str_detect(Systems, as.character(input$slct)))

    })

}

Option 2:

You can use validate() and need make requirements and suggest user input.

server <- function(input, output) {
    #df$system<-rownames(df$Systems)
    output$mytable = DT::renderDataTable({
        validate(need(input$slct,"Please Select System")) # add this line
        df %>%
            filter(stringr::str_detect(Systems, as.character(input$slct)))

    })

}

Read those two articles for more information:

  1. https://shiny.rstudio.com/articles/validation.html
  2. https://shiny.rstudio.com/articles/req.html
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!