R和Shiny:将滑块的输入传递到反应函数以计算输出
我有6个参数,用户可以更改其值。这是我们的6个输入。 我想创建一个输出值,它接受这6个输入并计算我们感兴趣的值,给定函数中的一些相关方程。以下是我的UI中的内容R和Shiny:将滑块的输入传递到反应函数以计算输出,r,function,output,shiny,R,Function,Output,Shiny,我有6个参数,用户可以更改其值。这是我们的6个输入。 我想创建一个输出值,它接受这6个输入并计算我们感兴趣的值,给定函数中的一些相关方程。以下是我的UI中的内容 library(shiny) # Define UI for slider demo application shinyUI(pageWithSidebar( # Application title headerPanel("# Header Title Goes Here"), # Sidebar with sliders t
library(shiny)
# Define UI for slider demo application
shinyUI(pageWithSidebar(
# Application title
headerPanel("# Header Title Goes Here"),
# Sidebar with sliders that demonstrate various available options
sidebarPanel(
# Simple integer interval
sliderInput("u1", "Name:",
min=0, max=10000, value=10000),
#There are 6 slider inputs...
),
# Show a table summarizing the values entered
mainPanel(
tableOutput("values"),
uiOutput("focal"))
)
)
这是我服务器中的内容。R
library(shiny)
shinyServer(function(input, output) {
# Reactive expression to compose a data frame containing all of the values
sliderValues <- reactive({
# Compose data frame
data.frame(
Name = # Names of my 6 parameters,
Value = # inputs based on my 6 values by `input$value`,
stringsAsFactors=FALSE)
})
f <- renderText({function(r1, r2, r3, d1, d2, u1) #these are my 6 values
{ #List of equations that compute f based on the 6 values
}
})
# Show the values using an HTML table
output$values <- renderTable({
sliderValues()
})
# Show the final calculated value
output$focal <- renderText({
f
})
})
库(闪亮)
shinyServer(功能(输入、输出){
#反应式表达式组成包含所有值的数据帧
sliderValues我认为这里有一些混淆。首先,在server.R
中定义f
的地方,我认为您只需要按照通常的方式定义一个函数。然后,当您执行renderText()
时,可以调用该函数来获取您的值
按照现在的方式,您正在renderText()中创建一个函数
,然后您试图让renderText
显示它,而不给它参数。这就是为什么您会收到错误消息,因为renderText
将其第一个参数传递给cat
,后者不知道如何处理函数。但是,它可以处理函数的输出
不管怎样,下面的内容对我来说很有用。我只做了两个滑块,但是你可以自己扩展它
ui.R:
服务器.R
#server.R
library(shiny)
shinyServer(function(input, output) {
# Reactive expression to compose a data frame containing all of the values
sliderValues <- reactive({
# Compose data frame
data.frame(
Name = c("u1", "r1"),
Value = c(input$u1,
input$r1),
stringsAsFactors=FALSE)
})
f <- function(u1, r1) {
u1 + r1
}
# Show the values using an HTML table
output$values <- renderTable({
sliderValues()
})
# Show the final calculated value
output$focal <- renderText(
{f(input$u1, input$r1)}
)
})
#server.R
图书馆(闪亮)
shinyServer(功能(输入、输出){
#反应式表达式组成包含所有值的数据帧
sliderValues HOLY COW!!这完全有效!!非常感谢!!!我为此工作了一整天!!!非常感谢你!!!!!祝你有一个美好的一天!反应UI是另一回事™为什么这是一个商标短语?
#server.R
library(shiny)
shinyServer(function(input, output) {
# Reactive expression to compose a data frame containing all of the values
sliderValues <- reactive({
# Compose data frame
data.frame(
Name = c("u1", "r1"),
Value = c(input$u1,
input$r1),
stringsAsFactors=FALSE)
})
f <- function(u1, r1) {
u1 + r1
}
# Show the values using an HTML table
output$values <- renderTable({
sliderValues()
})
# Show the final calculated value
output$focal <- renderText(
{f(input$u1, input$r1)}
)
})