Shiny 如何计算从滑块接收值的数学表达式

Shiny 如何计算从滑块接收值的数学表达式,shiny,shinyapps,Shiny,Shinyapps,我是新来的,我正在努力学习。我的问题是,我想通过给滑块一个值来计算一个数学表达式,最后显示结果。直到现在,我已经做了以下代码,但它是错误的。你能给我引路吗 提前谢谢 library(shiny) library(shinythemes) # Define UI for slider demo app ---- ui <- fluidPage( #Navbar structure for UI navbarPage("SAR Model", theme = sh

我是新来的,我正在努力学习。我的问题是,我想通过给滑块一个值来计算一个数学表达式,最后显示结果。直到现在,我已经做了以下代码,但它是错误的。你能给我引路吗

提前谢谢

library(shiny)
library(shinythemes)

# Define UI for slider demo app ----
ui <- fluidPage(
  #Navbar structure for UI
  navbarPage("SAR Model", theme = shinytheme("united"),
             tabPanel("Toblers Function", fluid = TRUE),
             # App title ----
             titlePanel("Toblers Fuction"),
             
             # Sidebar layout with input and output definitions ----
             sidebarLayout(
               
               # Sidebar to demonstrate various slider options ----
               sidebarPanel(
                 
                 # Input: Slope interval with step value ----
                 sliderInput("slope", "Slope:",
                             min = -0.60, max = 0.50,
                             value = 0.0, step = 0.01),
                 
               ),
               
               # Main panel for displaying outputs ----
               mainPanel( 
                 
                 # Output: Table summarizing the values entered ----
                 tableOutput("values")
                 
               )
             )
  )
)

server <- function(input, output, session) {
  
  # Reactive expression to create data frame off input value ----
  sliderValues <- reactive({
    
    data.frame(
      Name = c("Slope"),
      
      Value = as.character(c(input$slope)),
      stringsAsFactors = FALSE)
  })
  
  Value$toblers <- 6*exp(-3.5*input$slope)
  
  
  # Show the values in an HTML table ----
  output$values <- renderTable({
    sliderValues()
  })
  
  output$tobler <-renderText({value$toblers})
  
}
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(shinythemes)
#定义滑块演示应用程序的UI----

ui在不允许的被动上下文之外使用
输入$slope
。为toblers的计算定义一个反应式,然后显示如下:

toblers <- reactive({
            6*exp(-3.5*input$slope)
})

output$tobler <-renderText({toblers()})

toblers好的,我做了一些更改,但没有显示结果。
这是密码

library(shiny)
library(shinythemes)

# Define UI for slider demo app ----
ui <- fluidPage(
  #Navbar structure for UI
  navbarPage("SAR Model", theme = shinytheme("united"),
             tabPanel("Toblers Function", fluid = TRUE),
             # App title ----
             titlePanel("Toblers Fuction"),
             
             # Sidebar layout with input and output definitions ----
             sidebarLayout(
               
               # Sidebar to demonstrate various slider options ----
               sidebarPanel(
                 
                 # Input: Slope interval with step value ----
                 sliderInput("slope", "Slope:",
                             min = -0.60, max = 0.50,
                             value = 0.0, step = 0.01)),
          
               
               # Main panel for displaying outputs ----
               mainPanel( 
                 
                 # Output: Table summarizing the values entered ----
                 tableOutput("values"),
                 
            
               )
             )
  )
)

server <- function(input, output, session) {
  
  # Reactive expression to create data frame off input value ----
  sliderValues <- reactive({
    
    data.frame(
      Name = c("Slope"),
      
      Value = as.character(c(input$slope)),
      stringsAsFactors = TRUE)
  })
 
  
 
  # Show the values in an HTML table ----
  output$values <- renderTable({
    sliderValues()
  })
  output$slope <- renderText({
    paste0("The speed is ", 6*exp(-3.5*input$slope),"Km/h")
  })
  
 }
shinyApp(ui = ui, server = server)
library(shiny)
library(shinythemes)

# Define UI for slider demo app ----
ui <- fluidPage(
  #Navbar structure for UI
  navbarPage("SAR Model", theme = shinytheme("united"),
             tabPanel("Toblers Function", fluid = TRUE),
             # App title ----
             titlePanel("Toblers Fuction"),
             
             # Sidebar layout with input and output definitions ----
             sidebarLayout(
               
               # Sidebar to demonstrate various slider options ----
               sidebarPanel(
                 
                 # Input: Slope interval with step value ----
                 sliderInput("slope", "Slope:",
                             min = -0.60, max = 0.50,
                             value = 0.0, step = 0.01)),
               
               
               # Main panel for displaying outputs ----
               mainPanel( 
                 
                 # Output: Table summarizing the values entered ----
                 tableOutput("Values"),
                 tableOutput("slope")
                 
                 
               )
             )
  )
)

server <- function(input, output, session) {
  
  # Reactive expression to create data frame off input value ----
  sliderValues <- reactive({
    
    data.frame(
      Name = c("Slope"),
      
      Value = as.character(c(input$slope)),
      stringsAsFactors = TRUE)
  })
  
  
  
  # Show the values in an HTML table ----
  output$values <- renderTable({
    sliderValues()
  })
  output$slope <- renderText({
    paste0("The speed is ", 6*exp(-3.5*abs(input$slope+0.05)),"Km/h")
  })
}
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(shinythemes)
#定义滑块演示应用程序的UI----

ui我找到了一个解决方案,但不知道该表是否显示了来自滑块的值。 有什么意见吗?为什么? 这是密码

library(shiny)
library(shinythemes)

# Define UI for slider demo app ----
ui <- fluidPage(
  #Navbar structure for UI
  navbarPage("SAR Model", theme = shinytheme("united"),
             tabPanel("Toblers Function", fluid = TRUE),
             # App title ----
             titlePanel("Toblers Fuction"),
             
             # Sidebar layout with input and output definitions ----
             sidebarLayout(
               
               # Sidebar to demonstrate various slider options ----
               sidebarPanel(
                 
                 # Input: Slope interval with step value ----
                 sliderInput("slope", "Slope:",
                             min = -0.60, max = 0.50,
                             value = 0.0, step = 0.01)),
          
               
               # Main panel for displaying outputs ----
               mainPanel( 
                 
                 # Output: Table summarizing the values entered ----
                 tableOutput("values"),
                 
            
               )
             )
  )
)

server <- function(input, output, session) {
  
  # Reactive expression to create data frame off input value ----
  sliderValues <- reactive({
    
    data.frame(
      Name = c("Slope"),
      
      Value = as.character(c(input$slope)),
      stringsAsFactors = TRUE)
  })
 
  
 
  # Show the values in an HTML table ----
  output$values <- renderTable({
    sliderValues()
  })
  output$slope <- renderText({
    paste0("The speed is ", 6*exp(-3.5*input$slope),"Km/h")
  })
  
 }
shinyApp(ui = ui, server = server)
library(shiny)
library(shinythemes)

# Define UI for slider demo app ----
ui <- fluidPage(
  #Navbar structure for UI
  navbarPage("SAR Model", theme = shinytheme("united"),
             tabPanel("Toblers Function", fluid = TRUE),
             # App title ----
             titlePanel("Toblers Fuction"),
             
             # Sidebar layout with input and output definitions ----
             sidebarLayout(
               
               # Sidebar to demonstrate various slider options ----
               sidebarPanel(
                 
                 # Input: Slope interval with step value ----
                 sliderInput("slope", "Slope:",
                             min = -0.60, max = 0.50,
                             value = 0.0, step = 0.01)),
               
               
               # Main panel for displaying outputs ----
               mainPanel( 
                 
                 # Output: Table summarizing the values entered ----
                 tableOutput("Values"),
                 tableOutput("slope")
                 
                 
               )
             )
  )
)

server <- function(input, output, session) {
  
  # Reactive expression to create data frame off input value ----
  sliderValues <- reactive({
    
    data.frame(
      Name = c("Slope"),
      
      Value = as.character(c(input$slope)),
      stringsAsFactors = TRUE)
  })
  
  
  
  # Show the values in an HTML table ----
  output$values <- renderTable({
    sliderValues()
  })
  output$slope <- renderText({
    paste0("The speed is ", 6*exp(-3.5*abs(input$slope+0.05)),"Km/h")
  })
}
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(shinythemes)
#定义滑块演示应用程序的UI----
用户界面