【发布时间】:2019-03-16 06:08:19
【问题描述】:
我刚刚开始尝试使用 Shiny。我想做的事情看起来很容易,但我做不到。
我只想得到两个用逗号分隔的值字符串,然后,当按下操作按钮“go”时,将这些字符串转换为数字向量,并绘制一个对另一个。
问题似乎是字符串到数字向量的转换。在 R 中,我通常使用以下行并且可以正常工作
x<-"2,4,6,98"
y<-as.numeric(unlist(strsplit(x,",")))
y
[1] 2 4 6 98
但是当“eventReactive”中包含相同的内容时,我得到了
as.double 中的错误:无法将“闭包”类型强制转换为“double”类型的向量
这是我试过的代码:
library(shiny)
ui <- fluidPage(
titlePanel("Plot data"),
sidebarPanel(
textInput(inputId = "Conc",label="measured concentrations",value="",
placeholder ="Enter a numeric vector, comma separated"),
textInput(inputId = "Time",label="Time", value="",
placeholder ="Enter a numeric vector, comma separated"),
actionButton("go","Go!")
),
mainPanel(
plotOutput(outputId = "plot1")
)
)
server<-function(input, output){
t<-eventReactive(input$go,{as.numeric(unlist(strsplit(input$Time,",")))})
parent<-eventReactive(input$go,{as.numeric(unlist(strsplit(input$Conc,",")))})
pp<-reactive({plot(t,parent)})
output$plot1 <- renderPlot({pp()})
}
shinyApp(ui=ui,server=server)
感谢任何帮助!
【问题讨论】: