使用selectInput-based dynamic Parameter将绘图从rmarkdown复制到Shining时出现的问题
我在使用selectInput-based dynamic Parameter将绘图从rmarkdown复制到Shining时出现的问题,r,shiny,selectinput,R,Shiny,Selectinput,我在rmarkdown中创建了一个绘图,我正在使用selectInPut在shinny中使用动态参数重新创建它。我面临着一些问题,由于字符串和非字符串类型,我猜我不能弄清楚 可从以下网址获取数据: r标记代码和绘图: vaccination_data %>% filter(date == max(date)) %>% slice_max(order_by = total_vaccinations, n = 20) %>% ggplot(aes(x =
rmarkdown
中创建了一个绘图,我正在使用selectInPut
在shinny
中使用动态参数重新创建它。我面临着一些问题,由于字符串和非字符串类型,我猜我不能弄清楚
可从以下网址获取数据:
r标记代码和绘图:
vaccination_data %>%
filter(date == max(date)) %>%
slice_max(order_by = total_vaccinations, n = 20) %>%
ggplot(aes(x = total_vaccinations,
y = fct_reorder(location, total_vaccinations),
col = continent)) +
geom_point() +
geom_errorbarh(height=0, size=1, aes(xmin=total_vaccinations, xmax=0)) +
scale_x_continuous(labels = unit_format(scale = 1e-6, unit = "M")) +
geom_vline(xintercept = 0, col = "midnightblue", lty = 2, size = 1) +
theme(
panel.grid.major = element_blank(),
legend.position = "NULL")
output$top_vaccinating_countries <- renderPlot({
req(input$id_vaccination_top_country)
vaccination_data %>%
filter(date == max(date)) %>%
slice_max(order_by = input$id_vaccination_top_country, n = 20) %>%
ggplot(aes(x = input$id_vaccination_top_country,
y = fct_reorder(location, input$id_vaccination_top_country),
col = continent)) +
geom_point() +
geom_errorbarh(height=0, size=1,
aes(xmin=as.numeric(!! sym(input$id_vaccination_top_country)) ,
xmax=0)) +
# scale_x_continuous(labels = unit_format(scale = 1e-6, unit = "M")) +
geom_vline(xintercept = 0, col = "midnightblue", lty = 2, size = 1) +
scale_color_tableau() +
theme(
panel.grid.major = element_blank(),
legend.position = "top",
legend.direction = "horizontal")
})
column(4, style = "border: 1px solid gray;",
selectInput(inputId = "id_vaccination_top_country",
label = "Select Vaccination Parameter",
choices = c("total_vaccinations",
"total_vaccinations_per_hundred",
"people_vaccinated",
"people_vaccinated_per_hundred"),
selected = "total_vaccinations"),
plotOutput("top_vaccinating_countries", height = "570px")
)
library(shiny)
library(shinydashboard)
library(shinythemes)
library(highcharter)
library(streamgraph)
# library(thematic)
#
# thematic_shiny(font = "auto")
# Define UI for application
shinyUI(fluidPage(
theme=shinytheme("lumen"),
themeSelector(),
navbarPage(
title = "Covid19 Dashboard",
id = "Covid19_Dashboard",
tabPanel("Global Cases Status",
# Application title
titlePanel("Global level"),
fluidRow(
style = "border: 1px solid gray;",
column(4, style = "border: 1px solid gray;",
plotOutput("top_CFR_countries", height = "650px")),
column(4, style = "border: 1px solid gray;",
plotOutput("top_testing_countries", height = "650px")
),
column(4, style = "border: 1px solid gray;",
selectInput(inputId = "id_vaccination_top_country",
label = "Select Vaccination Parameter",
choices = c("total_vaccinations",
"total_vaccinations_per_hundred",
"people_vaccinated",
"people_vaccinated_per_hundred"),
selected = "total_vaccinations"),
plotOutput("top_vaccinating_countries", height = "570px")
)
)
) # navbarpage
) # fluid page
) # shiny ui
在上面的代码中,我试图将total_munizations
参数设置为动态的
server.R:
vaccination_data %>%
filter(date == max(date)) %>%
slice_max(order_by = total_vaccinations, n = 20) %>%
ggplot(aes(x = total_vaccinations,
y = fct_reorder(location, total_vaccinations),
col = continent)) +
geom_point() +
geom_errorbarh(height=0, size=1, aes(xmin=total_vaccinations, xmax=0)) +
scale_x_continuous(labels = unit_format(scale = 1e-6, unit = "M")) +
geom_vline(xintercept = 0, col = "midnightblue", lty = 2, size = 1) +
theme(
panel.grid.major = element_blank(),
legend.position = "NULL")
output$top_vaccinating_countries <- renderPlot({
req(input$id_vaccination_top_country)
vaccination_data %>%
filter(date == max(date)) %>%
slice_max(order_by = input$id_vaccination_top_country, n = 20) %>%
ggplot(aes(x = input$id_vaccination_top_country,
y = fct_reorder(location, input$id_vaccination_top_country),
col = continent)) +
geom_point() +
geom_errorbarh(height=0, size=1,
aes(xmin=as.numeric(!! sym(input$id_vaccination_top_country)) ,
xmax=0)) +
# scale_x_continuous(labels = unit_format(scale = 1e-6, unit = "M")) +
geom_vline(xintercept = 0, col = "midnightblue", lty = 2, size = 1) +
scale_color_tableau() +
theme(
panel.grid.major = element_blank(),
legend.position = "top",
legend.direction = "horizontal")
})
column(4, style = "border: 1px solid gray;",
selectInput(inputId = "id_vaccination_top_country",
label = "Select Vaccination Parameter",
choices = c("total_vaccinations",
"total_vaccinations_per_hundred",
"people_vaccinated",
"people_vaccinated_per_hundred"),
selected = "total_vaccinations"),
plotOutput("top_vaccinating_countries", height = "570px")
)
library(shiny)
library(shinydashboard)
library(shinythemes)
library(highcharter)
library(streamgraph)
# library(thematic)
#
# thematic_shiny(font = "auto")
# Define UI for application
shinyUI(fluidPage(
theme=shinytheme("lumen"),
themeSelector(),
navbarPage(
title = "Covid19 Dashboard",
id = "Covid19_Dashboard",
tabPanel("Global Cases Status",
# Application title
titlePanel("Global level"),
fluidRow(
style = "border: 1px solid gray;",
column(4, style = "border: 1px solid gray;",
plotOutput("top_CFR_countries", height = "650px")),
column(4, style = "border: 1px solid gray;",
plotOutput("top_testing_countries", height = "650px")
),
column(4, style = "border: 1px solid gray;",
selectInput(inputId = "id_vaccination_top_country",
label = "Select Vaccination Parameter",
choices = c("total_vaccinations",
"total_vaccinations_per_hundred",
"people_vaccinated",
"people_vaccinated_per_hundred"),
selected = "total_vaccinations"),
plotOutput("top_vaccinating_countries", height = "570px")
)
)
) # navbarpage
) # fluid page
) # shiny ui
我尝试了各种组合的(!!sym(input$)
,但没有成功。甚至尝试了varSelectInput
,但如果我这样做,则会出现另一个错误:
varSelectInput(
data = (vaccination_data %>% select(total_vaccinations, people_vaccinated))
更新用户界面:
vaccination_data %>%
filter(date == max(date)) %>%
slice_max(order_by = total_vaccinations, n = 20) %>%
ggplot(aes(x = total_vaccinations,
y = fct_reorder(location, total_vaccinations),
col = continent)) +
geom_point() +
geom_errorbarh(height=0, size=1, aes(xmin=total_vaccinations, xmax=0)) +
scale_x_continuous(labels = unit_format(scale = 1e-6, unit = "M")) +
geom_vline(xintercept = 0, col = "midnightblue", lty = 2, size = 1) +
theme(
panel.grid.major = element_blank(),
legend.position = "NULL")
output$top_vaccinating_countries <- renderPlot({
req(input$id_vaccination_top_country)
vaccination_data %>%
filter(date == max(date)) %>%
slice_max(order_by = input$id_vaccination_top_country, n = 20) %>%
ggplot(aes(x = input$id_vaccination_top_country,
y = fct_reorder(location, input$id_vaccination_top_country),
col = continent)) +
geom_point() +
geom_errorbarh(height=0, size=1,
aes(xmin=as.numeric(!! sym(input$id_vaccination_top_country)) ,
xmax=0)) +
# scale_x_continuous(labels = unit_format(scale = 1e-6, unit = "M")) +
geom_vline(xintercept = 0, col = "midnightblue", lty = 2, size = 1) +
scale_color_tableau() +
theme(
panel.grid.major = element_blank(),
legend.position = "top",
legend.direction = "horizontal")
})
column(4, style = "border: 1px solid gray;",
selectInput(inputId = "id_vaccination_top_country",
label = "Select Vaccination Parameter",
choices = c("total_vaccinations",
"total_vaccinations_per_hundred",
"people_vaccinated",
"people_vaccinated_per_hundred"),
selected = "total_vaccinations"),
plotOutput("top_vaccinating_countries", height = "570px")
)
library(shiny)
library(shinydashboard)
library(shinythemes)
library(highcharter)
library(streamgraph)
# library(thematic)
#
# thematic_shiny(font = "auto")
# Define UI for application
shinyUI(fluidPage(
theme=shinytheme("lumen"),
themeSelector(),
navbarPage(
title = "Covid19 Dashboard",
id = "Covid19_Dashboard",
tabPanel("Global Cases Status",
# Application title
titlePanel("Global level"),
fluidRow(
style = "border: 1px solid gray;",
column(4, style = "border: 1px solid gray;",
plotOutput("top_CFR_countries", height = "650px")),
column(4, style = "border: 1px solid gray;",
plotOutput("top_testing_countries", height = "650px")
),
column(4, style = "border: 1px solid gray;",
selectInput(inputId = "id_vaccination_top_country",
label = "Select Vaccination Parameter",
choices = c("total_vaccinations",
"total_vaccinations_per_hundred",
"people_vaccinated",
"people_vaccinated_per_hundred"),
selected = "total_vaccinations"),
plotOutput("top_vaccinating_countries", height = "570px")
)
)
) # navbarpage
) # fluid page
) # shiny ui
有几个地方应该将字符串更改为
sym
bol并对其求值(!!
)
-用户界面
-输出
我认为在
aes
中,对于ggplot
,sym!!没有i..e!!rlang::sym(输入$id\U疫苗接种\U top\U国家)
也在fct\U reorder
中,也就是说,它将是ggplot(aes(x=!!rlang::sym(输入$id\U疫苗接种\U top国家),y=fct\U reorder(位置,!!rlang::sym(输入$id\U疫苗接种\U top国家)),col=col))
谢谢@akrun,但即使如此,它仍然会给出相同的结果。您可以显示uiyes的完整代码吗?我会更新。我已经添加了ui部分的相关部分,因为完整的ui相当长。如果你还想让我展示这一点,那么我将更新完整的ui代码。非常感谢@akrun提供如此详细的解释。非常感谢您的详细努力。我总是被这些rlang字符串和符号概念搞混。如果你曾经遇到任何关于这些概念的好链接,或者在同一个网站上制作任何视频,那么请分享。再次非常感谢:)