【发布时间】:2018-02-27 05:35:33
【问题描述】:
我看不到数据表作为输出,既看不到整个数据,也看不到使用反应函数选择的数据。数据集是由函数Merton 在 Shiny 应用程序内生成的。我尝试为数据集“mod”使用几个对象类,但它不起作用。
代码如下:
library(shiny)
server <- function(input,output, session) {
library(ggplot2)
library(DT)
library(CreditRisk)
Maturity <- c(0.5, 1, 2, 3, 5, 10, 15, 20, 25, 30, 35)
mod <- Merton(L = 10, V0 = 20, sigma = 0.2, r = 0.005, t = Maturity)
output$plot <- renderPlot({
ggplot(mod, aes(Maturity, mod$Surv))+ geom_point()
})
dat <- reactive({
user_brush <- input$user_brush
sel.data <- brushedPoints(mod, user_brush)
return(sel.data)
})
output$table <- DT::renderDataTable(DT::datatable(dat()))
output$mydownload <- downloadHandler(
filename = "plotextract.csv",
content = function(file) {
write.csv(dat(), file)})
}
ui <- fluidPage(
h3("Exporting Data as .csv"),
plotOutput("plot", brush = "user_brush"),
dataTableOutput("table"),
downloadButton(outputId = "mydownload", label = "Download Table")
)
shinyApp(ui = ui, server = server)
【问题讨论】:
-
也许这有帮助:
DT::dataTableOutput("table") -
我在dataTableOutput("table")之前加了DT::,结果不行
-
将表格放入反应空间:output$table
-
谢谢,但不起作用