闪亮的多个目标

multiple objectives in shiny

您好,我对 shiny 比较陌生。我正在开发一个基本应用程序,它采用不同股票的投资组合 returns 并对这些投资组合进行 PCA returns 该应用程序应该显示 table 不同的主要成分并打印主要组件的摘要也是如此,但它只显示 table 而不是主要组件的摘要。 这是我的代码


library(shiny)
server = function(input, output, session) {
  output$print<-renderTable({
    ticker<-c(input$STOCK1, input$STOCK2, input$STOCK3, input$STOCK4)
    portfolioPrice <- NULL
    for(ticker in ticker) {
      portfolioPrice <- cbind(portfolioPrice,
                              getSymbols.yahoo(ticker,  periodicity = 'daily', auto.assign=FALSE)[,6])
    }
    poty=na.omit(ROC(portfolioPrice))
    op=prcomp(poty, scale. = T)
    dadsa=op$rotation
    axz=as.table(dadsa)

    return(axz)
  })

  output$out<-renderPrint({
    ticker<-c(input$STOCK1, input$STOCK2, input$STOCK3, input$STOCK4)
    portfolioPrice <- NULL
    for(ticker in ticker) {
      portfolioPrice <- cbind(portfolioPrice,
                              getSymbols.yahoo(ticker,  periodicity = 'daily', auto.assign=FALSE)[,6])
    }
    poty=na.omit(ROC(portfolioPrice))
    op=prcomp(poty, scale. = T)


    waps=summary(op)
    return(waps)
  })







} # the server

ui = basicPage(
  textInput("STOCK1", "STOCK 1","AAL"),
  textInput("STOCK2","STOCK 2","NULL" ),
  textInput("STOCK3", "STOCK 3" ,"NULL" ),
  textInput("STOCK4","STOCK4"),
  tableOutput("print")
  textOutput("out")
) # the user interface

shinyApp(ui = ui, server = server) # perform app launch


这是应用程序的图片,您可以看到它获取库存并显示 table 主要组件

但该应用并未打印本应如下所示的主要组件摘要

请帮忙,我将非常感激,我相信这会帮助其他试图学习闪亮的编码员

使用 verbatimTextOutput 而不是 textoutput :

library(shiny)
library(quantmod)
server = function(input, output, session) {
  output$print<-renderTable({
    ticker<-c(input$STOCK1, input$STOCK2, input$STOCK3, input$STOCK4)
    portfolioPrice <- NULL
    for(ticker in ticker) {
      portfolioPrice <- cbind(portfolioPrice,
                              getSymbols.yahoo(ticker,  periodicity = 'daily', auto.assign=FALSE)[,6])
    }
    poty=na.omit(ROC(portfolioPrice))
    op=prcomp(poty, scale. = T)
    dadsa=op$rotation
    axz=as.table(dadsa)

    return(axz)
  })

  output$out<-renderPrint({}
    ticker<-c(input$STOCK1, input$STOCK2, input$STOCK3, input$STOCK4)
    portfolioPrice <- NULL
    for(ticker in ticker) {
      portfolioPrice <- cbind(portfolioPrice,
                              getSymbols.yahoo(ticker,  periodicity = 'daily', auto.assign=FALSE)[,6])
    }
    poty=na.omit(ROC(portfolioPrice))
    op=prcomp(poty, scale. = T)
    waps=summary(op)
    return(waps)
  })
} # the server

ui = basicPage(
  textInput("STOCK1", "STOCK 1","AAL"),
  textInput("STOCK2","STOCK 2","NULL" ),
  textInput("STOCK3", "STOCK 3" ,"NULL" ),
  textInput("STOCK4","STOCK4"),
  tableOutput("print"),
  verbatimTextOutput ("out")  #Use `verbatimTextOutput` instead of `textoutput`
) # the user interface

shinyApp(ui = ui, server = server)