我正在尝试让R处于闪亮状态,根据单选按钮的选择为每个国家绘制不同的y值(每个可能的y值组都在我的.csv中作为自己的列)。即使名称完全匹配(如下所示),它似乎也不起作用,或者我在ggplot图中的输出$ data中调用它。请帮忙!
library(shiny)
library(tidyverse)
library(readr)
Emissions <- read_csv("~/Desktop/CAIT Country GHG Emissions.csv")
ui <- fluidPage(
titlePanel("Greenhouse Gas Emissions Emissions by Country, 1990-2014"),
radioButtons("data", "Include:", choices = c("total",
"total_including_landuse", "co2_only")
),
sidebarLayout( sidebarPanel( selectInput("country","Country:", choices
= Emissions$Country)
),
mainPanel(
plotOutput("emitPlot"),
)
) )
server <- function(input, output) {
output$emitPlot <- renderPlot({
emissions = input$data
ggplot(subset(Emissions, Country == input$country, ), aes(x =Year, y =
emissions ###(THIS IS THE PART I'M TRYING TO FIX, it should be like y=
input$data, or something###
))+
geom_col(aes(fill = Year))+
xlab("Year")+
ylab("GHG Emissions (Metric tons, CO2 Equivellent)")+
theme_classic()
}) }
shinyApp(ui = ui, server = server)
答案 0 :(得分:2)
function f(){ return f; }
new f() instanceof f;
是一个字符串,而input$data
使用非标准评估来捕获变量名称。我们可以使用aes
代替。下面给出了aes_string()
数据集的工作示例。希望这有帮助!
mtcars