R 选择器输入反应性问题

R 选择器输入反应性问题,r,shiny,shiny-reactivity,R,Shiny,Shiny Reactivity,我的皮肤反应性有问题。在我的UI中,我有 library(tidyverse) library(shiny) library(forcats) ui <- fluidPage( titlePanel(h1("Percent Cover")), selectInput("selectInput", "Select Site", choices = c("A", "B", "C", "D")), plotOutput("coverTypeBarChart", height

我的皮肤反应性有问题。在我的UI中,我有

library(tidyverse)
library(shiny)
library(forcats)

ui <- fluidPage(

  titlePanel(h1("Percent Cover")),

  selectInput("selectInput", "Select Site", choices = c("A", "B", "C", "D")), 


plotOutput("coverTypeBarChart", height = "600px")

)
库(tidyverse)
图书馆(闪亮)
图书馆(供猫用)

ui我同意p0bs-您需要将
反应式表达式的结果分配给变量

另外,嵌套的
if…else
语句具有特定的语法
else
必须与
if
语句的右大括号在同一行

以下是一些可能有效的方法:

data <- reactive({
    if(input$selectInput == "A"){
        A
    } else if(input$selectInput == "B") {
        B
    } else if(input$selectInput == "C") {
        C
    } else if(input$selectInput == "D") {
        D
    }
})

data我最近不得不解决一个类似的问题。对于以下示例,我编写了一些数据:

library(shiny)
library(ggplot2)

set.seed(1)
A <- sample_frac(mtcars,0.2) %>% select(cyl)
B <- sample_frac(mtcars,0.2) %>% select(cyl)
C <- sample_frac(mtcars,0.2) %>% select(cyl)
D <- sample_frac(mtcars,0.2) %>% select(cyl)
我使用的技巧是通过
name
get
检索所需的data.frame。例如:

get("A")

                 cyl
Merc 230           4
Merc 450SE         8
Fiat 128           4
Porsche 914-2      4
Valiant            6
Pontiac Firebird   8
服务器的上下文中

server <- function( input, output ) {
               output$barchart <- renderPlot(ggplot(data = get(input$choice), aes(cyl)) + geom_bar())
          }

server我不能说太多,因为我没有数据帧的示例。然而,从我所看到的,我看不出你在你的反应功能上附加了什么。你是否需要说以下几句话<代码>数据
get("A")

                 cyl
Merc 230           4
Merc 450SE         8
Fiat 128           4
Porsche 914-2      4
Valiant            6
Pontiac Firebird   8
server <- function( input, output ) {
               output$barchart <- renderPlot(ggplot(data = get(input$choice), aes(cyl)) + geom_bar())
          }