I've made an application shiny and I want to plot the graph with ggplo2.
My question is :
when I use the script below in my shiny application, I obtain the GRAPH A (see below) that's wrong!
when I use the same script directly in rstudio I obtained the GRAPH B, that is good!
WHY don't I the same graph? Have you an idea?
Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.
If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.
Preparing reprex as .R file:
* test_reprex.R
Rendering reprex...
Writing reprex markdown:
* test_reprex.md
Error in file(con, "w") : cannot open the connection
In addition: Warning messages:
1: In readLines(path) : incomplete final line found on '1_10.R'
2: In file(con, "w") :
cannot open file 'test_reprex.utf8.md': Invalid argument
About reprex, please, follow the beginner guide about reprex from the FAQ. Try to identify your issue and build a small example.
also this webinar is recent and can help you build a reprex
We can help you if you can help us help you, and only in the scope of our Homework Policy.
Giving folks a reprex will certainly help. A few thoughts without knowing anything about your data:
You should drop the print(perf.project.tdy) line of code, as that appears to just be a leftover from your original attempts to check your work. It might be causing problems in the Shiny app.
Why have you elected to create an object p outside of the primary dataframe? My suspicion is that separating the X and Y variables into distinct objects (i.e., a dataframe and a vector) is causing mischief here. I think you'd be better served using the forcats package to convert perf.project.tdy$pas into a factor and releveling it, rather than creating a separate object.
Consider chaining all your code together into a single pipeline using %>%. It would help to make your code more readable and leaner.
The ggplot2 documentation recommends using geom_col with stat="identity", while geom_bar is more suitable for stat="count". You also don't really need the position="stack" parameter here, as you're not attempting to create stacked bars in any case.
2- I used a variable p as factor because I have a message error if I don't use it.
3 - I'm not sure to do understand. How can I use the pipeline %>% out of my output.
4 - You are right, it's not necessary to use position="stack"
I found my issue.
In reactive fiunction I calculate perf.project.tdy$perfand I add "%" If I leave the"%" the value is not a numuric. If I take off "%" it's OK.
How can I leave the ratio value with the symbol "%" to plot my function?
Thanks in advance
PS : I tried to use reprex. I installed the package reprex and there is a error message : reprex is unknown function
For more flexible number formatting, see the scales package
If you’d like help getting the reprex package installed and working, please open a separate topic for that question. Note that since this was about a problem in a shiny app, formatting your example with reprex would not have worked. Shiny reproducible examples are a bit more complicated to create. See this FAQ for help: Shiny debugging and reprex guide.
However, the same basic principles apply: if people can’t run your code, then in most cases they can’t figure out your problem. Here, it was impossible for anybody else to find the problem since it turned out to be in a part of the shiny app code that you didn’t include in your post. It’s not very efficient for you to have helpers stuck just guessing what might be wrong due to incomplete information, and it’s not terribly respectful of your helpers’ time, either.