r - 如何在R中改变闪亮的曲线
问题描述
我想更改数字以使情节动画化。我试过这个
library(shiny)
library(ggplot2)
ui <- fluidPage(
titlePanel("Equation"),
sidebarLayout(
sidebarPanel(
sliderInput(inputId = "values",
label = "number of values:",
min = -5,
max = 5,
value = 5)
),
mainPanel(
plotOutput(outputId = "distPlot")
)
)
)
server <- function(input, output) {
output$distPlot <- renderPlot({
k <- function(x,c) {
p <- (-x^3+c)
return(p)
}
gg <- function(c_val) {
ggplot(data.frame(x = c(-50, 50)), aes(x)) +
stat_function(fun = k, args = list(c=c_val), aes(colour = "temp"))}
gg(-5)
})
}
shinyApp(ui,server)
我可以看到情节和侧边栏,但是当我移动侧边栏时,它不会改变。我努力改变剧情。我知道它可能不会发生重大变化,但对于这些代码的目的来说并不重要。
我想知道我们是否可以使用闪亮来做到这一点。
解决方案
您需要为您的 ggplot 提供输入:替换gg(-5)
为gg(input$values)
. 正如评论中所说,由于您的滑块只是更改曲线的偏移量,因此您需要适当的比例来查看更改。我将其设置为 -5:5:
library(shiny)
library(ggplot2)
ui <- fluidPage(
titlePanel("Equation"),
sidebarLayout(
sidebarPanel(
sliderInput(inputId = "values",
label = "number of values:",
min = -5,
max = 5,
value = 5)
),
mainPanel(
plotOutput(outputId = "distPlot")
)
)
)
server <- function(input, output) {
output$distPlot <- renderPlot({
k <- function(x,c) {
p <- (-x^3+c)
return(p)
}
gg <- function(c_val) {
ggplot(data.frame(x = c(-5, 5)), aes(x)) +
stat_function(fun = k, args = list(c=c_val), aes(colour = "temp"))}
gg(input$values)
})
}
shinyApp(ui,server)
推荐阅读
- android - 模糊库 - 如何模糊单个视图?
- excel - 如何使用 VBA 变量在 VLookup 中跨多个工作簿的查找值
- r - 如何使用 ggplot barplot 绘制表函数的结果(x 轴值问题)
- redundancy - 您能否在现有的 Apache Geode 区域上增加复制?
- sql-server - 在“)”附近预期条件的上下文中指定的非布尔类型的表达式
- r - 如何使用 r 中的 lavaan 包获取 CFA 中因子的相关矩阵和 p 值?
- javascript - res.redirect 错误 [ERR_HTTP_HEADERS_SENT]:在将标头发送到客户端后无法设置标头
- python-3.x - 在linux系统上构建python包后如何访问资源文件
- sas - 网格单元的 SAS 点计数
- vue.js - 如果我的变量是数组,如何更改 vuex 中的状态