如何在 R studio(闪亮的应用程序)中的 max() 函数中传递输入?
How to pass an Input inside a max() function in R studio (shiny App)?
我正在尝试将输入 input$sel
传递给 max() 函数
max(dataf$get(input$sel))
已知 dataf
是具有值的数据框。
我的目标是通过 select 输入 input$sel
.
从 dataf
的列中获取最大值
server <- function(input, output, session) {
#Summarize Data and then Plot
data <- reactive({
req(input$sel)
df <- dataf %>%
group_by(code) %>%
summarise(output = get(input$sel))
print(df)
})
#Plot
output$plot <- renderPlot({
g <- ggplot(data(), aes(y = output, x = code) )
g + geom_bar( stat = "sum")
})
}
ui <- basicPage(
selectInput(inputId = "sel",
label = "eine möglichkeit auswählen",
list("vaccinationsTotal","peopleFirstTotal","peopleFullTotal","peopleBoosterTotal")),
plotOutput("plot")
###### here is my approuch ##########
max(dataf$get(input$sel))
)
输入值仅在应用服务器内部可用。更恰当地说,他们需要 observe/reactive.
提供的反应上下文
试试这个:
注意:我使用 iris
数据集作为虚拟数据以使代码可重现。
library(shiny)
library(tidyverse)
ui <- basicPage(
selectInput(
inputId = "sel",
label = "eine möglichkeit auswählen",
choices = names(iris)
),
# list("vaccinationsTotal","peopleFirstTotal","peopleFullTotal","peopleBoosterTotal")),
plotOutput("plot")
)
server <- function(input, output, session) {
# Summarize Data and then Plot
data <- reactive({
req(input$sel)
df <- iris %>%
group_by(Species) %>%
summarise(output = max(get(input$sel)))
print(df)
df
})
# Plot
output$plot <- renderPlot({
g <- ggplot(data(), aes(y = output, x = Species))
g + geom_bar(stat = "sum")
})
}
shinyApp(ui, server)
我正在尝试将输入 input$sel
传递给 max() 函数
max(dataf$get(input$sel))
已知 dataf
是具有值的数据框。
我的目标是通过 select 输入 input$sel
.
dataf
的列中获取最大值
server <- function(input, output, session) {
#Summarize Data and then Plot
data <- reactive({
req(input$sel)
df <- dataf %>%
group_by(code) %>%
summarise(output = get(input$sel))
print(df)
})
#Plot
output$plot <- renderPlot({
g <- ggplot(data(), aes(y = output, x = code) )
g + geom_bar( stat = "sum")
})
}
ui <- basicPage(
selectInput(inputId = "sel",
label = "eine möglichkeit auswählen",
list("vaccinationsTotal","peopleFirstTotal","peopleFullTotal","peopleBoosterTotal")),
plotOutput("plot")
###### here is my approuch ##########
max(dataf$get(input$sel))
)
输入值仅在应用服务器内部可用。更恰当地说,他们需要 observe/reactive.
提供的反应上下文试试这个:
注意:我使用 iris
数据集作为虚拟数据以使代码可重现。
library(shiny)
library(tidyverse)
ui <- basicPage(
selectInput(
inputId = "sel",
label = "eine möglichkeit auswählen",
choices = names(iris)
),
# list("vaccinationsTotal","peopleFirstTotal","peopleFullTotal","peopleBoosterTotal")),
plotOutput("plot")
)
server <- function(input, output, session) {
# Summarize Data and then Plot
data <- reactive({
req(input$sel)
df <- iris %>%
group_by(Species) %>%
summarise(output = max(get(input$sel)))
print(df)
df
})
# Plot
output$plot <- renderPlot({
g <- ggplot(data(), aes(y = output, x = Species))
g + geom_bar(stat = "sum")
})
}
shinyApp(ui, server)