关于创建
shiny app
我收到了下载数据的信息-
正在下载文件1/1:
transit_cost.csv
我已经使用了以下区块选项,但仍然收到以下消息:
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
我也尝试过下面的块选项,但它们也隐藏了plot&输入:
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE, results='hide', fig.keep='all')
如何抑制所有不需要的消息。只显示文件中的输入/输出?
此代码取自
作者:David Robinson:
https://youtu.be/8jNQzce13SE?t=2938
代码
---
title: "transit_Shiny"
output: html_document
runtime: shiny
---
knitr::opts\u chunk$set(echo=FALSE,message=FALSE,warning=FALSE)
library(tidyverse)
library(tidytuesdayR)
library(scales)
library(glue)
theme_set(theme_light())
library(countrycode)
library(shiny)
library(plotly)
library(tidytext)
tt <- tt_load("2021-01-05")
transit_cost <- tt$transit_cost %>%
filter(!is.na(e)) %>%
mutate_at(vars(start_year, end_year, real_cost), as.numeric) %>%
mutate(country_code = ifelse(country == "UK", "GB", country),
country = countrycode(country_code, "iso2c", "country.name"),
tunnel_per = tunnel / length,
rr = ifelse(rr, "Railroad", "Not Railroad"),
station_density = stations / length) %>%
mutate(country = fct_infreq(country))
按成本/公里计算,最昂贵的线路项目:
metrics <- c("Cost / KM (millions USD)" = "cost_km_millions",
"Length (KM)" = "length",
"Stations / KM" = "station_density")
inputPanel(
selectizeInput("country", label = "Country:",
choices = levels(transit_cost$country), selected = "India"),
selectInput("metric", label = "Metric:", choices = metrics, selected = metrics[1]),
sliderInput("num_lines", label = "# of lines to display:",
min = 1, max = 30, value = 16, step = 1)
)
transit_cost_country <- reactive({
transit_cost %>%
filter(country == input$country)
})
renderPlotly({
metric <- input$metric
x_axis_lab <- names(metrics)[metrics == metric]
g <- transit_cost_country() %>%
arrange(desc(!!sym(metric))) %>%
head(input$num_lines) %>%
mutate(line = reorder_within(line, !!sym(metric), city)) %>%
ggplot(aes(!!sym(metric), line, fill = city)) +
geom_col() +
scale_y_reordered() +
labs(x = x_axis_lab,
y = "",
color = "City")
if (metric %in% c("cost_km_millions")) {
g <- g + scale_x_continuous(labels = dollar)
}
ggplotly(g)
})