8

I'm trying to debug my Shiny app and would like to view a reactive dataframe with e.g. glimpse(df).

Initially I tried to create a breakpoint and then view the environment by my reactive df is a value not an object when used inside server.r. I also tried browser() but was not sure what it would do.

I did some searching on SO and tried various things using sink(), renderPrint() but had no success.

How can I print the contents of glimpse(some_reactive_df()) to the console when I run my app?

0

1 Answer 1

11

Calling print() from within the reactive({}) expression will do that.

library(shiny)

library(dplyr)

shinyApp(
    ui <- fluidPage(
        selectizeInput("cyl_select", "Choose ya mtcars$cyl ", choices = unique(mtcars$cyl)),

        tableOutput("checker") # a needed output in ui.R, doesn't have to be table
    ),
    server <- function(input, output) {

        d <- reactive({ 
            d <- dplyr::filter(mtcars, cyl %in% input$cyl_select)
            print(glimpse(d)) # print from within
            return(d)
            })

    output$checker <- renderTable({
        glimpse(d()) # something that relies on the reactive, same thing here for simplicty
    })
    })

Assuming you provide Shiny a reason to run (and re-run) your reactive of interest, by having it be involved with a rendering in server() and linked output in ui(). This is usually the case for my debugging scenarios but it won't work unless the reactive is being used elsewhere in app.R.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.