我最近修改了 R Shiny 应用程序中
server
脚本中的几行。该代码通过长 paste0
函数创建文本,其中包括“硬编码”文本以及通过引用在应用程序中其他位置创建的数据对象 (data.tab1
) 动态更新的数字。现在,粘贴的文本会重复两次(即出现三次而不是一次)。
我想知道是否有人可以查看代码并查看导致文本重复的原因。我知道这是很好的做法,但在这种情况下,我根本无法提供
reprex
: 如果我知道如何复制错误,我就会知道如何解决问题。
以下是应用程序中重复文本的样子:
这是新代码:
output$snapshottext <- renderUI({
HTML(
paste0("<h3>",
rv$selectedCounty,
" County faces climate change exposures that pose considerable health risks to the population, especially to a number of vulnerable groups. </h3>
<h2><font color='#3182bd'>Environmental Exposures</font></h2>
<p>More frequent extreme weather patterns will pose a hazard to ",
rv$selectedCounty,
" County's population health. If greenhouse gas emissions continue to grow as they have in the past, the number of <strong>extreme heat days</strong> over ",
round(data.tab1()$numratr[data.tab1()$ind_strt == 'heat_2040-2060']*9/5+32, 1),
"°F are expected to be ",
round(data.tab1()$County_Value[data.tab1()$ind_strt == 'heat_2040-2060'], 0),
" days per year in 2040-2060 and ",
round(data.tab1()$County_Value[data.tab1()$ind_strt == 'heat_2080-2099'], 0),
" days per year in 2080-2099. Higher temperatures can also increase hazardous air pollution. In ",
data.tab1()$tperiod[data.tab1()$ind == 'ozone'],
", ",
rv$selectedCounty,
" County's average maximum <strong>ozone</strong> concentration was ",
round(data.tab1()$County_Value[data.tab1()$ind == 'ozone'], 3),
" ppm and average <strong>fine particulate matter</strong> (PM2.5) was ",
round(data.tab1()$County_Value[data.tab1()$ind == 'pm'], 1),
" µg/m3, which is ",
ifelse(data.tab1()$County_Value[data.tab1()$ind == 'pm'] < 12, 'lower', 'higher'),
" than the state standard of 12 µg/m3 (the statewide averages were ",
round(data.tab1()$CA_avg[data.tab1()$ind == 'ozone'], 3),
" ppm for ozone and ",
round(data.tab1()$CA_avg[data.tab1()$ind == 'pm'], 1),
" µg/m3 for PM2.5).</p>
<p>Higher temperatures and changes in precipitation are leading to longer, more severe droughts which, in turn, contribute to increased risk of <strong>wildfires</strong>. Around ",
round(data.tab1()$County_Value[data.tab1()$ind == 'wildfire'], 1),
"% (",
format(round(data.tab1()$numratr[data.tab1()$ind == 'wildfire'], 0),
big.mark = ",",
scientific = FALSE),
" residents) of the ",
rv$selectedCounty,
" County population lived in very high wildfire risk areas in 2010 (statewide average was ",
round(data.tab1()$CA_avg[data.tab1()$ind == 'wildfire'], 0),
"%).</p>
<h2><font color='#d95f0e'>Population Sensitivity</font></h2>
<p>Certain populations will experience the health impacts of climate change earlier, more often, or more severely, such as <strong>children and elderly</strong>, and those with disabilities. In ",
data.tab1()$tperiod[data.tab1()$ind == 'children'],
", ",
rv$selectedCounty,
" County's population included ",
round(data.tab1()$County_Value[data.tab1()$ind == 'children'], 1),
"% children (",
format(round(data.tab1()$numratr[data.tab1()$ind == 'children'], 0),
big.mark = ",",
scientific = FALSE),
" persons under 5) and ",
round(data.tab1()$County_Value[data.tab1()$ind == 'elderly'], 1),
"% elderly (",
format(round(data.tab1()$numratr[data.tab1()$ind == 'elderly'], 0),
big.mark = ",",
scientific = FALSE),
" persons 65 years and older) (state population included ",
round(data.tab1()$CA_avg[data.tab1()$ind == 'children'], 1),
"% children and ",
round(data.tab1()$CA_avg[data.tab1()$ind == 'elderly'], 1),
"% elderly). </p>
<p>Between ",
data.tab1()$tperiod[data.tab1()$ind == 'disability'],
", ",
round(data.tab1()$County_Value[data.tab1()$ind_strt == 'disability_physical'], 1),
"% (",
format(round(data.tab1()$numratr[data.tab1()$ind_strt == 'disability_physical'], 0),
big.mark = ",",
scientific = FALSE),
" people) of ",
rv$selectedCounty,
" County's population reported having <strong>physical disabilities</strong> (statewide average was ",
round(data.tab1()$CA_avg[data.tab1()$ind_strt == 'disability_physical'], 0),
"%). In ",
data.tab1()$tperiod[data.tab1()$ind == 'disability'],
", ",
rv$selectedCounty,
" County's population included ",
round(data.tab1()$County_Value[data.tab1()$ind_strt == 'disability_mental'], 1),
"% (",
format(round(data.tab1()$numratr[data.tab1()$ind_strt == 'disability_mental'], 0),
big.mark = ",",
scientific = FALSE),
" people) with <strong>mental disabilities</strong> (statewide average was ",
round(data.tab1()$CA_avg[data.tab1()$ind_strt == 'disability_mental'], 0),
"%).</p>
<p>Social or cultural isolation can also limit protective behaviors, community support, or the efficacy of emergency notifications during extreme weather and disasters. In ", data.tab1()$tperiod[data.tab1()$ind == 'linguistic'], ", ",
round(data.tab1()$County_Value[data.tab1()$ind == 'linguistic'], 1),
"% of the county's households were considered <strong>linguistically isolated</strong> (",
format(round(data.tab1()$numratr[data.tab1()$ind == 'linguistic'], 0),
big.mark = ",",
scientific = FALSE),
" households), where no one aged 14 or older spoke English (statewide average was ",
round(data.tab1()$CA_avg[data.tab1()$ind == 'linguistic'], 1),
"%). </p>
<p>Climate change and its impacts add to the cumulative stresses already experienced by populations without adequate financial resources, those living in communities with high incidence of violence, or who have limited access to supports like higher education, insurance, or personal transportation. In ", rv$selectedCounty, " County, ",
round(data.tab1()$County_Value[data.tab1()$ind == 'poverty'], 0),
"% (",
format(round(data.tab1()$numratr[data.tab1()$ind == 'poverty'], 0),
big.mark = ",",
scientific = FALSE),
" residents) of the <strong>population was living below 200% of the poverty level</strong> in ", data.tab1()$tperiod[data.tab1()$ind == 'poverty'], ", (statewide average was ",
round(data.tab1()$CA_avg[data.tab1()$ind == 'poverty'], 0),
"%). ",
rv$selectedCounty,
" County's <strong>violent crime rate</strong> in ",
data.tab1()$tperiod[data.tab1()$ind == 'crime'],
" was ",
round(data.tab1()$County_Value[data.tab1()$ind == 'crime'], 1),
" per 100,000 persons (statewide average was ",
round(data.tab1()$CA_avg[data.tab1()$ind == 'crime'], 1),
" per 100,000). In ", data.tab1()$tperiod[data.tab1()$ind == 'education'], ", ",
round(data.tab1()$County_Value[data.tab1()$ind == 'education'], 0),
"% of people (",
format(round(data.tab1()$numratr[data.tab1()$ind == 'education'], 0),
big.mark = ",",
scientific = FALSE),
" residents) in ",
rv$selectedCounty,
" County aged 25 years or older had an <strong>educational attainment</strong> of less than a four-year college degree (statewide average was ",
round(data.tab1()$CA_avg[data.tab1()$ind == 'education'], 1),
"%). In ",
data.tab1()$tperiod[data.tab1()$ind == 'insurance'],
", ",
round(data.tab1()$County_Value[data.tab1()$ind == 'insurance'], 0),
"% of the population (",
format(round(data.tab1()$numratr[data.tab1()$ind == 'insurance'], 0),
big.mark = ",",
scientific = FALSE),
" residents) in the county were <strong>without health insurance</strong> (statewide average was ", round(data.tab1()$CA_avg[data.tab1()$ind == 'insurance'], 1), "%). Please note that data is provided for ",
data.tab1()$tperiod[data.tab1()$ind == 'insurance'],
". This covers a time period both before and after the full implementation of the Affordable Care Act, which increased access to insurance. In ",
data.tab1()$tperiod[data.tab1()$ind == 'vehicles'],
", ",
round(data.tab1()$County_Value[data.tab1()$ind == 'vehicles'], 0),
"% of households (",
format(round(data.tab1()$numratr[data.tab1()$ind == 'vehicles'], 0),
big.mark = ",",
scientific = FALSE),
" households) <strong>lacked a personal vehicle</strong> (statewide average was ",
round(data.tab1()$CA_avg[data.tab1()$ind == 'vehicles'], 1),
"%). Finally, ",
round(data.tab1()$County_Value[data.tab1()$ind == 'outdoor'], 0),
"% (",
format(round(data.tab1()$numratr[data.tab1()$ind == 'outdoor'], 0),
big.mark = ",",
scientific = FALSE),
" workers) of ",
rv$selectedCounty,
" County's labor force <strong>worked outdoors</strong> in ",
data.tab1()$tperiod[data.tab1()$ind == 'outdoor'],
", and face an elevated risk to heat's effects on health (statewide average was ",
round(data.tab1()$CA_avg[data.tab1()$ind == 'outdoor'], 1),
"%).</p>
<h2><font color='#54278f'>Adaptive Capacity</font></h2>
<p>Adaptive capacity is important for responding to the impacts of climate change. Expanses of concrete and asphalt (<strong>impervious surfaces</strong>) make hot summers even hotter, while parks and trees can help make future heat waves more bearable.
In the portions of ",
rv$selectedCounty,
" County where people resided, the land was about ",
round(data.tab1()$County_Value[data.tab1()$ind == 'impervious'], 0),
"% impervious surfaces (",
data.tab1()$tperiod[data.tab1()$ind == 'impervious'],
" data) and ",
round(data.tab1()$County_Value[data.tab1()$ind == 'canopy'], 0),
"% areas without <strong>tree canopy cover</strong> (",
data.tab1()$tperiod[data.tab1()$ind == 'canopy'],
" data) (statewide averages were ",
round(data.tab1()$CA_avg[data.tab1()$ind == 'impervious'], 1),
"% and ",
round(data.tab1()$CA_avg[data.tab1()$ind == 'canopy'], 1),
"%, respectively). Access to public transit and <strong>air conditioning</strong> helps people relocate to cooler or safer spaces in the event of heat waves, extreme weather, or other events like wildfires. According to a ",
data.tab1()$tperiod[data.tab1()$ind == 'ac'],
" survey, ",
round(data.tab1()$County_Value[data.tab1()$ind == 'ac'], 0),
"% (",
format(round(data.tab1()$numratr[data.tab1()$ind == 'ac'], 0),
big.mark = ",",
scientific = FALSE),
" households) of households in ",
rv$selectedCounty,
" County did not have air conditioning (statewide average was ",
round(data.tab1()$CA_avg[data.tab1()$ind == 'ac'], 1),
"%). These findings highlight the aspects of vulnerability and the populations in ",
rv$selectedCounty,
" County most susceptible to health risks from current and future climate change exposures. Responding to and preparing for a changing climate presents opportunities for local health departments and partners to consider policies, actions, and infrastructure design that will not just protect the public, but also promote health equity, resiliency, and sustainability.</p>"
)
)
})
这是
ui
文件的相应文本:
tabPanel(
"County Snapshot",value = "county_snapshot",
# Create a new Row in the UI for selectInputs
##### Select a County #####
fluidRow(column(8, includeMarkdown("countyPlot.md")),
column(
2,
# selectInput("cnty1",
# "Select a County",
# c(sort(
# unique(as.character(CHVIdata$county))
# ))),
tags$h3(textOutput("CountyText2")),
p(uiOutput("downloadCHPR1"))
)),
fluidRow(column(
12,
wellPanel(
HTML("<h3> County compared to the state average</h3>"),
plotlyOutput("plotCounty", height = "800px"),
downloadLink(outputId = "downloadCountySnapshot", label = "Download the data in this figure")
)
)
# column(3,
# wellPanel(
# uiOutput("topindicators")
# ))
),
wellPanel(uiOutput("snapshottext")),
wellPanel(DT::dataTableOutput("countyTable"))
),
其中在
server
中创建的文本是 uiOutput
对象 snapshottext
。
所有修改(除了纠正一些拼写错误)都插入了动态更新的数字,而不是硬编码的数字。例如,
" County's population reported having <strong>physical disabilities</strong> (statewide average was 6%). In 2011-2015,",
rv$selectedCounty,
" County's population included ",
现在:
" County's population reported having <strong>physical disabilities</strong> (statewide average was ",
round(data.tab1()$CA_avg[data.tab1()$ind_strt == 'disability_physical'], 0),
"%). In ",
data.tab1()$tperiod[data.tab1()$ind == 'disability'],
", ",
其中
round(data.tab1()$CA_avg[data.tab1()$ind_strt == 'disability_physical'], 0)
替代“6%”,round(data.tab1()$CA_avg[data.tab1()$ind_strt == 'disability_physical'], 0)
替代“2011-2015”。
如果没有看到数据,我猜问题出在
paste()
中的项目。可能参数之一正在解析为长度为 3 的向量,而表达式的其余部分正在被回收。
尝试删除部分
paste()
表达式,直到重复消失,您应该能够将有问题的项目归零。