作者asdfrtg (asdfrtg)
看板R_Language
标题[问题] 如何使用shiny textInput()
时间Tue Dec 11 21:05:36 2018
[问题类型]:
程式谘询(我想用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://webptt.com/cn.aspx?n=bbs/R_Language/M.1544533545.A.FC3.html
1F:→ locka: 你input$index1的输入有几个? 12/12 08:07
2F:→ locka: textInput的话就算你输入["YHOO","QQQ"]还是会当成一个字串 12/12 08:37
3F:→ locka: 不知道是不是这个问题@@ 12/12 08:37
4F:→ 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
5F:推 alex13587: 推推大神HumuHumu 01/23 22:58