简体   繁体   中英

Failure to display DataTable in RShiny App

I'm hoping to display a reactive datatable for my Shiny app. I'm using renderDataTable() and have made sure that the data table is returned in the reactive function. I've noticed that the datatable renders fine outside of the Shiny App, so not a variable/computation error. The reason I'm hoping to use a datatable in the first place is so that I can display cleaned up column names and display the dataframe in a more clean manner. Please let me know what else I can try, or if I should change my approach.

Here is the server code:

server <- function(input, output) {

  dataset <- reactive({
    shiny_tuition_salary <- datatable(df_tuition_salary %>%
                                        select(name, mean_net_cost, state) %>%
                                        filter(mean_net_cost >= input$input_budget[1],
                                               mean_net_cost <= input$input_budget[2],
                                               state == input$input_state) %>%
                                        select(name, mean_net_cost))

    return(shiny_tuition_salary)
  })

  output$df <- renderDataTable({

    dataset()

  })

}

Currently nothing is displayed under the Table tab in the app. The app also successfully displays the table when DataTable is not used at all (ie removing datatable() from the server and using RenderTable instead of RenderDataTable), so I'm positive there's an issue with my implementation of RenderDataTable()

Thanks!

EDIT: Here's the ui code and a sample df_tuition_salary as well

ui <- fluidPage(

  titlePanel("What colleges match your budget and rank?"),

  # Sidebar laayout with input and output definitions ----
  sidebarLayout(

    # Sidebar panel for inputs ----
    sidebarPanel(

      # Input: Slider for the number of bins ----
      sliderInput(inputId = "input_budget",
                  label = "Budget:",
                  min = 0,
                  max = 50000,
                  value = c(0, 15000)),
      selectInput(inputId = "input_state",
                  label = "State (limited data, may limit options):",
                  choices = df_tuition_salary$state)

    ),

    # Main panel for displaying outputs ----
    mainPanel(
      tabsetPanel(
        id = 'output_df',
        # tabPanel("Plot", plotOutput("plot")),
        tabPanel("Table", tableOutput("df"))
      )

    )
  )
)

df_tuition_salary:

df_tuition_salary <- data.frame(name = c("Aaniiih Nakoda College", "Abilene Christian University"),
           mean_net_cost = c(7508.2414, 24884.0828),
           state = c("N/A", "N/A"))

use dataTableOutput() function.

# Main panel for displaying outputs ----
    mainPanel(
      tabsetPanel(
        id = 'output_df',
        # tabPanel("Plot", plotOutput("plot")),
        tabPanel("Table", dataTableOutput("df"))
      )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM