r - 代码不会对 R 中的闪亮变化进行动画处理
问题描述
我试图学习闪亮的结构来发展我的情节。经过几个小时的工作,我得到了感兴趣的情节,但是当我改变值时,我看不到情节有任何变化。
先感谢您!
以下是代码:
library(shiny)
df <- data_frame(x = c("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O"
),
y = c(45,55,66,55,45,45,50,50,50,64,44,60,50,50,45))
ui <- fluidPage(
titlePanel("letters"),
sidebarLayout(
sidebarPanel(
tags$b("Data:"),
textInput("x", "x", value = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O", placeholder = "Enter letter separated by a comma, A,B,C"),
textInput("y", "y", value = "45,55,66,55,45,45,50,50,50,64,44,60,50,50,45", placeholder = "Enter values separated by a comma with decimals as points, e.g. 50, 55.5, 5, 5.03, etc."),
),
mainPanel(
plotOutput("distPlot")
)
))
server<-shinyServer(function(input, output) {
output$distPlot <- renderPlot({
df2 <- ave(df$y, df$y, FUN = seq_along)
plot(df2 ~ df$y, df, pch = df$x, ylim = c(1, 20), ylab = "", axes = FALSE)
axis(1)
mu <- mean(df$y)
abline(v = mu, col = "red")
text(mu, 20, paste("Avg time:", mu), adj = -0.1, col = "red")
})
})
shinyApp(ui = ui, server = server)
解决方案
如果您想更改数据框传递input$x
并input$y
在服务器内部创建一个数据框以使其对更改做出反应。例如:
library(shiny)
library(stringr)
library(dplyr)
ui <- fluidPage(
titlePanel("letters"),
sidebarLayout(
sidebarPanel(
tags$b("Data:"),
textInput("x", "x", value = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O", placeholder = "Enter letter separated by a comma, A,B,C"),
textInput("y", "y", value = "45,55,66,55,45,45,50,50,50,64,44,60,50,50,45", placeholder = "Enter values separated by a comma with decimals as points, e.g. 50, 55.5, 5, 5.03, etc."),
),
mainPanel(
plotOutput("distPlot"),
"This is a brief description text" # can add other elements
)
))
server<-shinyServer(function(input, output) {
output$distPlot <- renderPlot({
df <- data_frame(x = input$x %>% str_split(",", simplify = TRUE) %>% str_trim(),
y = input$y %>% str_split(",", simplify = TRUE) %>% str_trim() %>% as.numeric())
df2 <- ave(df$y, df$y, FUN = seq_along)
plot(df2 ~ df$y, df, pch = df$x, ylim = c(1, 20), ylab = "", axes = FALSE)
axis(1)
mu <- mean(df$y)
abline(v = mu, col = "red")
text(mu, 20, paste("Avg time:", mu), adj = -0.1, col = "red")
})
})
shinyApp(ui = ui, server = server)
(这里使用了两个额外的包:dplyr
和stringr
)
推荐阅读
- flutter - 颤振从 CarouselSlider 中移除左侧间隙
- navigation - SwiftUI:使用 .onTapGuesture{} 导航到另一个视图
- mysql - 将字符串相似度与大量记录进行比较
- c# - 使用对象复活处理非托管资源的共享所有权
- angular - R3InjectorError(DynamicTestModule)[Store -> Store]: NullInjectorError: No provider for Store
- python - 无法在 Ubuntu 20.04 中安装 mysql-python 库
- powerbi - powebi:获取与其他列中每个值关联的值的数量
- c++ - 我正在尝试用c++创建一个货币转换程序,我不知道如何继续
- salesforce - Salesforce 入站短信集成
- ios - 为什么 SQLite 方法“sqlite3_step”不起作用