r - 无法使用 Plotly 和 Shiny 显示误差线
问题描述
我正在尝试用 Shiny 和 plotly 在散点图上显示误差线。这是我的 server.R 文件中的代码:
data = reactiveVal()
observe({
results <- data.frame() # actually getting the data from here
# formatting output
final.results <- cbind(
"id" = paste(results$a,
results$b,
results$c,
sep = '-'),
"sigma" = sprintf("%.5g", results$s),
"c-e" = sprintf("%.3g",results$calc - results$exp)
)
data(final.results)
})
output$plot <- renderPlotly(
as.data.frame(data()[,c("id", "c-e", "sigma")]) %>% plot_ly(
x = ~`c-e`,
y = ~id,
height = 800,
type = 'scatter',
mode = 'markers',
marker = list(color = "#90AFD9"),
error_x = list(array = ~sigma, color = "#000000", type = "data")
)
)
情节还可以,只是没有显示误差线,我的错误是什么?
编辑:澄清函数的起源及其data()
返回值是什么。
解决方案
该sprintf()
函数返回一个字符串,而不是一个数字,这就是它不将sigma
值显示为错误栏的原因。如果要保留 5 位小数,请改用该round()
函数:
"sigma" = round(results$s, digits = 5)
推荐阅读
- pandas - 仅对具有特定列值的行求和
- c# - SerializeException : 试图反序列化一个空流错误
- react-native - Algolia 和 React Native FlatList ListHeaderComponent
- scala - 在 Scala 中避免 asInstanceOf 的一种方法
- c# - 在 Task.IsCompleted 之后更好:await 或 Result
- python - 将所有标签值远离轴
- c# - 命令“call npm run build-templates”退出,代码为 134
- php - 这是 PHP 空合并运算符中的错误还是预期行为?
- python - 数据框中的乘法
- ios - Lottie 动画没有出现 iOS