R 我们可以在同一个面板中打印或绘图吗?

R 我们可以在同一个面板中打印或绘图吗?,r,shiny,R,Shiny,我想打两个电话 output$IPLMatchPlot <- renderPlot({ f(x) } 或 函数fx返回绘图或数据帧 我可以在server.R中单独执行此操作,但希望显示为数据帧的绘图或文本。任何关于如何实现这一点的建议都可以通过使用renderi来处理,renderi检查它获得的输出类型并呈现适当的输出 在UI部件中,您可以将uiOutput放置在希望打印或打印显示的位置 uiOutput("Plotorprint") 然后在服务器中,您可以使用以下内容定义ui

我想打两个电话

 output$IPLMatchPlot <- renderPlot({ 

 f(x)
} 或

函数fx返回绘图或数据帧


我可以在server.R中单独执行此操作,但希望显示为数据帧的绘图或文本。任何关于如何实现这一点的建议都可以通过使用renderi来处理,renderi检查它获得的输出类型并呈现适当的输出

在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
    }
  })
你也可以将你在问题中发布的定义保存在你的服务器上


然后,这应该检查fx获得的输出,并渲染适当的输出。

这可以通过使用Renderi来处理,Renderi检查它获得的输出类型并渲染适当的输出

在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
    }
  })
你也可以将你在问题中发布的定义保存在你的服务器上


然后应该检查fx得到的输出,并呈现适当的输出。

基于@Marjin响应的最终代码是

服务器.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")
    }
})

基于@Marjin响应的最终代码是

服务器.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")
    }
})

@Marjin-解决方案看起来不错,但我遇到了一些问题。我在ui中添加了。R-uiOutput'Plotorprint'&在服务器中。R仅打印文本的以下行==>output$Plotorprint我将在明天查看此输出$IPLMatchPlot,我在添加上述注释后意识到我使用了“renderPlot”而不是“renderPrint”。我改变了它,它成功了。。像魔术一样!谢谢@Marjin-解决方案看起来不错,但我遇到了一些问题。我在ui中添加了。R-uiOutput'Plotorprint'&在服务器中。R仅打印文本的以下行==>output$Plotorprint我将在明天查看此输出$IPLMatchPlot,我在添加上述注释后意识到我使用了“renderPlot”而不是“renderPrint”。我改变了它,它成功了。。像魔术一样!谢谢