【发布时间】:2020-03-12 16:39:11
【问题描述】:
我想要一个条形图 i R / Shiny 有动态。 我选择了一个国家,然后我只想查看这个国家的数据。 我已经创建了一些 R 代码,但是缺少国家选择和条形图之间的关系。
server.R 文件
library(datasets)
salg <- read_excel("C:\\Users\\Tue Hellstern\\Documents\\Demo\\Demo\\data\\SalgsData.xlsx", sheet = "salgs_data")
# Define a server for the Shiny app
function(input, output) {
output$selected_var <- renderText({
paste("You have selected", input$valgtLand)
})
# Fill in the spot we created for a plot
output$salgplot <- renderPlot({
# Render a barplot
salg %>%
ggplot(aes(x=CompanyType, y=Total)) +
geom_bar(stat="identity")
})
}
ui.R 文件
library(datasets)
salg <- read_excel("C:\\Users\\Tue Hellstern\\Documents\\Demo\\Demo\\data\\SalgsData.xlsx", sheet = "salgs_data")
# Use a fluid Bootstrap layout
fluidPage(
# Give the page a title
titlePanel("Salg efter kundetype"),
# Generate a row with a sidebar
sidebarLayout(
# Define the sidebar with one input
sidebarPanel(helpText("Du har mulighed for at vaelge kun at se et bestemt land"),
selectInput("valgtland", h3("Vaelg land"),
choices = salg$Country,
selected = 1)),
# Create a spot for the barplot
mainPanel(
plotOutput("salgplot")
)
)
)
我得到了这个布局,但是如何进行选择 // 条形图关系?
【问题讨论】: