我有一个navbarPage
,我有三个navbarMenu
.但是第一个,navbarMenu
即"帮助"总是默认突出显示,并且navbarMenu
tabpanel
"手动"也始终突出显示.如何避免这种情况.示例代码如下所示
ui.r
shinyUI(fluidPage(theme = "bootstrap.css",
(navbarPage("B Version",
position = c("fixed-top"),
fluid=TRUE,
navbarMenu("Help",
tabPanel(
a("Manual",
target="_blank", href="Manual.pdf")
),
tabPanel(
a("Supporte",
target="_blank", href="gpl.pdf")
),
tabPanel(
a("Tutorials",
downloadLink("AbE", "Expression", class=" fa fa-cloud-download"),
downloadLink("DiEx", "Expression", class=" fa fa-cloud-download")
)
)
),
navbarMenu("Sample Data",
tabPanel(
downloadLink("AData", " Aff", class=" fa fa-cloud-download")
),
tabPanel(
downloadLink("CData", " Code", class=" fa fa-cloud-download")
),
tabPanel(
downloadLink("IData", " Il", class=" fa fa-cloud-download")
)
),
navbarMenu("Stand-Alone Version",
tabPanel(
downloadLink("CodeandData", " app", class=" …
Run Code Online (Sandbox Code Playgroud) 我的闪亮应用程序的www目录中有一个PDF.我希望该文件可供下载.我怎样才能做到这一点.
下载示例运行良好,但不知道将其用于从www目录下载PDF.
## Only run examples in interactive R sessions
if (interactive()) {
ui <- fluidPage(
downloadLink("downloadData", "Download")
)
server <- function(input, output) {
# Our dataset
data <- mtcars
output$downloadData <- downloadHandler(
filename = function() {
paste("data-", Sys.Date(), ".csv", sep="")
},
content = function(file) {
write.csv(data, file)
}
)
}
shinyApp(ui, server)
}
Run Code Online (Sandbox Code Playgroud) 我想在一个中有三个元素unordered_map
.我尝试了以下代码
#include <iostream>
#include <string>
#include <algorithm>
#include <boost/unordered_map.hpp>
typedef boost::unordered_map<int, std::pair<int, int>> mymap;
mymap m;
int main(){
//std::unordered_map<int, std::pair<int, int> > m;
m.insert({3, std::make_pair(1,1)});
m.insert({4, std::make_pair(5,1)});
for (auto& x: m)
std::cout << x.first << ": "<< x.second << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
但是我在print语句中遇到了很多错误
'std :: pair'不是来自'const std :: __ cxx11 :: basic_string <_CharT,_Traits,_Alloc>'std :: cout << x.first <<":"<< x.second << std: :ENDL;
我想知道用于计算哈希值的公式Boost.Bimap
.例如,如果我想知道并手动计算整数123456
,或位集1101001
或字符串abcda
.
我试图以二进制格式编写文件.我有以下代码,但它以文本格式保存文件.
#include <iostream>
#include <fstream>
using namespace std;
int main(){
std::string ref = "Ecoli. 123";
unsigned int size = 124;
std::ofstream supp_info_output("binary_file", std::ios::out | std::ios::binary); // saving file
supp_info_output << ref << std::endl;
supp_info_output << size << std::endl;
supp_info_output.close();
std::ifstream supp_info_input("binary_file", std::ios::in | std::ios::binary); // loading file
std::string supp_info_line;
while( std::getline( supp_info_input, supp_info_line ).good() ){
std::cout << supp_info_line << std::endl;
}
supp_info_input.close();
}
Run Code Online (Sandbox Code Playgroud)
在代码中,我正在编写一些数据,然后再次读取数据.读写没有问题,但我需要二进制格式的文件.
我期待用整数元素替换字符串的元素.我要替换A
与1
,B
与2
,C
与3
和D
使用4
.
我怎样才能有效地做到这一点?
#include <iostream>
#include <string>
#include <algorithm>
int main()
{
std::string str = "ABCDDCBA";
std::replace(str.begin(), str.end(), 'A', '1'); // Replacing
std::replace(str.begin(), str.end(), 'B', '2');
std::replace(str.begin(), str.end(), 'C', '3');
std::replace(str.begin(), str.end(), 'D', '4');
// ...
std::cout << str << std::endl; // displaying
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我试图将setw
字符串输出的设置宽度用于输出文件,但是,我无法使其工作.我跟我有以下例子.
// setw example
#include <iostream>
#include <iomanip>
#include <fstream>
int main () {
std::ofstream output_file;
output_file.open("file.txt");
output_file << "first" <<std::setw(5)<< "second"<< std::endl;
output_file.close();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编辑:
对于上述行我预计将有很多空间之间first
和second
,像
first second
我几乎看不到任何空格,输出就像firstsecond
我想我错过了工作setw()
注意:对于整数,它只能正常工作:
output_file << 1 <<std::setw(5)<< 2 << std::endl;
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
我有一个,如果选择是两个并且打开,tabsetPanel()
我会尝试隐藏一个。我尝试使用以下代码来执行此操作,但它不起作用。tabPanel()
checkbox
用户界面
shinyUI(
fluidPage(
titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
fluidRow(
column(5,
radioButtons("radio", label = h5("Data uploaded"),
choices = list("Aff" = 1, "Cod" = 2,
"Ill" = 3),selected = 1)
)),
checkboxInput("checkbox", "cheb", value = F)
),
mainPanel(
tabsetPanel(
tabPanel("Plot", "plot1"),
conditionalPanel(
condition = "input.radio !=2 && input.checkbox == false",
tabPanel("Summary", "summary1")
),
tabPanel("Table", "table1")
)
)
)
)
)
Run Code Online (Sandbox Code Playgroud)
服务器
shinyServer(function(input,output,session){
})
Run Code Online (Sandbox Code Playgroud)
我怎样才能隐藏一个tabPanel()
?
我想检查一段代码所花费的时间.有没有办法做到这一点.我想知道所有的时间,比如(user, system, and elapsed)
我的代码的一小部分时间.说我的代码有不同的部分
code 1......
...........
...........
code2.........
...............
...............
所以我想要时间code 1
.谢谢
我想让程序等待,直到它完成所有正在运行的线程ioService.stop();
,这与一样,ioService
无需等待即可停止。我尝试了以下代码,该代码工作正常,但ioService
无需等待线程完成即可停止。
#include <iostream>
#include <boost/asio/io_service.hpp>
#include <boost/bind.hpp>
#include <boost/thread/thread.hpp>
void myTask (std::string &str);
int main(int argc, char **argv){
uint16_t total_threads = 4;
/*
* Create an asio::io_service and a thread_group
*/
boost::asio::io_service ioService;
boost::thread_group threadpool;
/*
* This will start the ioService processing loop.
*/
boost::asio::io_service::work work(ioService);
/*
* This will add threads to the thread pool.
*/
for (std::size_t i = 0; i < total_threads; ++i)
threadpool.create_thread(
boost::bind(&boost::asio::io_service::run, &ioService));
/*
* This will …
Run Code Online (Sandbox Code Playgroud) c++ ×5
r ×4
shiny ×3
boost ×2
string ×2
binaryfiles ×1
boost-asio ×1
boost-thread ×1
download ×1
hash ×1
integer ×1
profiling ×1
replace ×1
setw ×1