我正在尝试调试我的 Shiny 应用程序,并想查看一个反应式数据框,例如:glide(df)。
最初我尝试创建一个断点,然后通过我的反应式 df 查看环境,当在 server.r 中使用时,它是一个值而不是一个对象。我也尝试过,browser()
但不确定它会做什么。
我对 SO 进行了一些搜索,并使用 sink()、renderPrint() 尝试了各种方法,但没有成功。
glimpse(some_reactive_df())
运行应用程序时如何将 的内容打印到控制台?
Nat*_*ate 10
print()
从reactive({})
表达式内部调用将做到这一点。
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
})
})
Run Code Online (Sandbox Code Playgroud)
假设你提供闪亮的理由运行(并重新运行)您感兴趣的反应,有它在渲染参与server()
和链接的输出ui()
。这通常是我的调试场景的情况,但除非在app.R
.