我想或者調用我們可以在同一個面板中以Shiny打印還是繪圖?
output$IPLMatchPlot <- renderPlot({
f(x)
}) 或
output$IPLMatchPrint <- renderPrint({
f(x)
})
的函數f(x)或者返回一個情節或一個數據幀。
我能夠在server.R中單獨執行此操作,但希望顯示爲圖形或數據框的文本。如何做到這一點的任何建議
我想或者調用我們可以在同一個面板中以Shiny打印還是繪圖?
output$IPLMatchPlot <- renderPlot({
f(x)
}) 或
output$IPLMatchPrint <- renderPrint({
f(x)
})
的函數f(x)或者返回一個情節或一個數據幀。
我能夠在server.R中單獨執行此操作,但希望顯示爲圖形或數據框的文本。如何做到這一點的任何建議
這可以通過使用renderUI()來處理,它檢查它得到的輸出類型並呈現相應的輸出。
在UI部分中,您可以將uiOutput
放置在想要顯示圖或打印的位置。
uiOutput("Plotorprint")
,然後在服務器中,你會定義uiOutput
像這樣的東西:
output$Plotorprint <- renderUI({
if (is.data.frame(f(x))) { # Check if output of f(x) is data.frame
verbatinTextOutput("ISPLMatchPrint") # If so, create a print
} else { # If not,
plotOutput("ISPLMatchPlot") # create a plot
}
})
而你也讓你在你的問題在你的服務器發佈,以及定義。
然後這應該檢查輸出f(x)正在獲取,並呈現適當的輸出。
基於@ Marjin的響應最後的代碼是
server.R
output$IPLMatchPlot <- renderPlot({
f(x,y,z)
})
output$IPLMatchPrint <- renderPrint({
df <- f(x,y,z)
df
})
output$plotOrPrint <- renderUI({
if(is.data.frame(scorecard <- printOrPlot(input, output,teams, otherTeam))){
verbatimTextOutput("IPLMatchPrint")
}
else{
plotOutput("IPLMatchPlot")
}
})
ui.R
uiOutput("plotOrPrint"),
@Marjin - 該解決方案看起來正確的,但我遇到的問題。我加入了ui。 R - uiOutput('Plotorprint')&在server.R中用於僅打印文本的以下行==>輸出$ Plotorprint < - renderUI({ a <-f(x) verbatimTextOutput(a)})。這將打印一個空框 –
我會看看明天這個輸出 –
$ IPLMatchPlot < - renderPlot({ printOrPlot(輸入,輸出,團隊,otherTeam) }) 輸出$ IPLMatchPrint < - renderPlot({ DF < -printOrPlot(輸入,輸出,團隊,其他團隊) df })output $ Plotorprint < - renderUI if {is.data.frame(scorecard < - printOrPlot(input,output,teams,otherTeam))){ verbatimTextOutput(「IPLMatchPrint」) } else { plotOutput(「IPLMatchPlot」) }該圖顯示但不是數據幀 –