【发布时间】:2018-04-21 05:09:45
【问题描述】:
我有一个函数 identify_IP(),它返回一个 1- 数据帧列表 2-ggplot。我需要在 ShinyApp 中渲染表和渲染图。这个 shinyApp 代码只呈现数据帧。但我无法渲染情节。有什么帮助吗?
library(shiny)
source('InflectionP2.R', local = TRUE)
runApp(
list(
ui = fluidPage(
titlePanel("Upload your file"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose xls file',
accept = c(".XLS")),
actionButton("btn", "Update Table"),
actionButton("btn1", "Display Plot"),
downloadButton('downloadData', 'Download')
),
mainPanel(
tableOutput('what'),
plotOutput('pl'))
)
)
,
server = function(input, output, session){
dataOP <- reactive({
inFile <- input$file1
if (is.null(input$file1))
return(NULL)
Identify_IP(read.table(inFile$datapath))
list(tble = df1, txt = inflection_points, plt = p )
})
observeEvent(input$btn, output$what <- renderTable({dataOP()$tble}))
observeEvent(input$btn1, output$pl <- renderPlot({
plot(dataOP()$plt)
}))
}
))
【问题讨论】:
-
您必须绘制
dataOP()$p,例如使用plot() -
你能提供更多细节吗?这与我已经做过的有什么不同?
-
顺便说一句,我不认为该列表有效,因为我尝试了 dataOP()$df1 并且没有呈现表格。所以我选择了 dataOP()
-
是的,列表可能需要移到
reactive({ ... })中。试试plot(dataOP()$p)之类的东西,或者你希望你的情节看起来像什么。 -
更具体地说:绘图命令需要在
renderPlot({ ... })内