闪亮的多个目标

时间:2020-03-27 02:03:01

标签: r shiny data-science shiny-server

你好,我对发亮还比较陌生。我正在开发一个基本应用程序,该应用程序可以获取不同股票的投资组合收益,并且对这些投资组合收益进行PCA处理时,该应用程序应该显示一张不同主要成分的表格,并打印出这些主要成分的摘要,但它仅显示该表不是主要组成部分的摘要。 这是我的代码


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


这是该应用程序的原始图片,您可以看到它提取了库存并显示了主要成分表enter image description here

但是该应用并未打印出应该看起来像这样的主要组成部分的摘要

enter image description here

请帮助我,我将非常感激,我相信这将帮助其他尝试学习闪亮技巧的程序员

1 个答案:

答案 0 :(得分:1)

使用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)