r - RStudio Server + Shiny - [没有可用的堆栈跟踪]
问题描述
我需要帮助,我正在努力学习闪亮,但我遇到了以下问题:我根本没有收到任何堆栈跟踪。即使我正在复制书中的示例:
https://mastering-shiny.org/action-workflow.html#tracebacks-in-shiny
我书中的闪亮代码只是为了测试堆栈跟踪:
library(shiny)
h <- function(x) x * 2
ui <- fluidPage(
selectInput("n", "N", 1:10),
plotOutput("plot")
)
server <- function(input, output, session) {
output$plot <- renderPlot({
n <- h(input$n)
plot(head(cars, n))
}, res = 96)
}
shinyApp(ui, server)
我收到的信息是:
Listening on http://127.0.0.1:7840
Warning: Error in *: non-numeric argument to binary operator
[No stack trace available]
R studio 服务器正在运行:10.4.1.252:8787
我的猜测是与 Shiny 连接的东西正在侦听本地 IP 地址(127.0.0.1)并且应用程序正在远程服务器上运行,我需要连接到 VPN 才能连接到该机器(以及 RStudio 服务器本身)
解决方案
该错误已经给您带来了问题:
selectInput 默认创建一个字符类输入(这可能会随着时间而改变)
有两种解决方法:
- 使用 as.numeric()
- 使用数字输入()
library(shiny)
h <- function(x) x * 2
ui <- fluidPage(
selectInput("n", "N", 1:10),
numericInput("n2", "Num input",1,min=1,max=10, step = 1), # solution 2
plotOutput("plot"),
textOutput("c1"),
textOutput("c2")
)
server <- function(input, output, session) {
output$plot <- renderPlot({
n <- h(as.numeric(input$n)) # solution 1
plot(head(cars, n))
}, res = 96)
# explanation:
output$c1<-renderText({class(input$n)})
output$c2<-renderText({class(as.numeric(input$n))})
output$c3<-renderText({class(input$n3)})
}
shinyApp(ui, server)
推荐阅读
- ionic4 - Razorpay 在 ionic 4 和 android 7.0.0 中不起作用
- youtube-api - YouTube API 未提供准确的视频结果
- symfony - 在 Doctrine 中使用映射的超类覆盖多对多关联
- javascript - 在谷歌数据视图中动态添加新列
- java - 从 void-visitor 返回数据而不更改抽象访问者
- android - 我想获取来电号码但号码为空
- python - 将字符串中的值替换为类似
只是清空''或什么都没有
- python - 删除多级列数据透视表python
- excel-formula - 如何构造我的 if 文本然后颜色语句
- excel - 从列表中随机选择单词,同时从列表中排除一个值