看板 R_Language 關於我們 聯絡資訊
[問題類型]: 程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來) [軟體熟悉度]: 使用者(已經有用R 做過不少作品) [問題敘述]: 想嘗試將ui端輸入的文字帶入函式中,按下執行鈕後出現錯誤 Warning: Error in [: incorrect number of dimensions 想請問出現此錯誤是因為server 與ui沒有對應到,或是帶入函式方法錯誤 [程式範例]: shinyServer( function(input, output,session) { library(rsconnect) library(tseries) library(quantmod) library(forecast) library(car) library(haven) observeEvent( input$goButton,{ index2<-as.character( input$index1) getSymbols(c(index2),from = "1900-01-05") index.open<-data.frame(as.numeric(c(index2)[,1])) index.open.year<-data.frame(tail(index.open,365)) colnames(index1.open.year)="OP.value" output$year.plot<-renderPlot(plot(index.open.year,main = "index plot")) output$value<-renderTable(data.frame(tail(index.open.year,5))) })}) library(shiny) library(rsconnect) shinyUI(fluidPage( titlePanel("index plot and table"), mainPanel( textInput( "index1",label = "index") , actionButton("goButton", "Go!"), plotOutput("year.plot"), tableOutput("value") ))) [環境敘述]: R 3.5 shiny [關鍵字]: shiny ui 輸入 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 175.96.98.58 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1544533545.A.FC3.html
locka: 你input$index1的輸入有幾個? 12/12 08:07
locka: textInput的話就算你輸入["YHOO","QQQ"]還是會當成一個字串 12/12 08:37
locka: 不知道是不是這個問題@@ 12/12 08:37
HumuHumu: 問題出在c(index2)[,1],你的index又不是dataframe 12/12 12:43
感謝! 因為第一次試按鈕以及文字輸入 後來使用 index3<-getSymbols(c(index2),from = "1900-01-05",auto.assign = FALSE) index.open<-data.frame(index3[,1])) 就成功了! ※ 編輯: asdfrtg (175.96.98.58), 12/14/2018 00:28:03
alex13587: 推推大神HumuHumu 01/23 22:58